Mathematical operators in postgresql
Mathematical operators in postgresql :
Multiplication Example :
>>Select pro_id,unit_order,unit_order * unit_price as order_cost from products
--this will multiply unit order and price in each column and add a new column with cost associated with each order.
--The idea that things in parentheses are handled first, then powers are --exponents, multiplication, division, addition, and subtraction. In the --United States, the popular mnemonic device, "Please excuse my dear Aunt --Sally", is often used.
>>Select pro_id,unit_order,(unit_order * (unit_price-prod_discount)) as order_cost from products;
>>Select pro_id,unit_order,(unit_price-discount)/Quantity as order_cost from products;
Aggregate Functions :
SUM,MIN,MAX,AVG are some example of aggregate functions.
So how do we use them ?
>>Select AVG(unit_price) as avg_price from products;
>>Select count(*) as total_customers from customers;
>>select count(customerID) as total_cus from customers;
>>select max(unit_price) as max_price, min(unit_price) as min_price from products;
--Now lets say you only want to count the distinct occurrences of a value then add DISTINCT
>>select count(Distinct customerID) as total_cus from customers;
Multiplication Example :
>>Select pro_id,unit_order,unit_order * unit_price as order_cost from products
--this will multiply unit order and price in each column and add a new column with cost associated with each order.
--The idea that things in parentheses are handled first, then powers are --exponents, multiplication, division, addition, and subtraction. In the --United States, the popular mnemonic device, "Please excuse my dear Aunt --Sally", is often used.
>>Select pro_id,unit_order,(unit_order * (unit_price-prod_discount)) as order_cost from products;
>>Select pro_id,unit_order,(unit_price-discount)/Quantity as order_cost from products;
Aggregate Functions :
SUM,MIN,MAX,AVG are some example of aggregate functions.
So how do we use them ?
>>Select AVG(unit_price) as avg_price from products;
>>Select count(*) as total_customers from customers;
>>select count(customerID) as total_cus from customers;
>>select max(unit_price) as max_price, min(unit_price) as min_price from products;
--Now lets say you only want to count the distinct occurrences of a value then add DISTINCT
>>select count(Distinct customerID) as total_cus from customers;
--remember you cannot use distinct with * in count
Comments
Post a Comment