W3 R4 Aggregate
W3 R4 Aggregate
✓ Count()
✓ Sum()
✓ Avg()
✓ Max()
✓ Min()
Aggregate Function – Count()
Customer
Customer
Count(Customer_Id)
Customer_Count
3
Aggregate Function – Count()
Example
SELECT count(DISTINCT City) AS City_Count
from Customer
Customer Customer
City_Count
4
Aggregate Function – Sum()
Example
SELECT Sum(Price) AS Total_Price
from Product
Product
Product Total_Price
14500
Aggregate Function – Avg()
Example
SELECT Avg(Price) AS Average_Price
from Product
Product
Product Average_Price
4833.3333
Aggregate Function – Min()
Example
SELECT Min(Price) AS Minimum_Price
from Product
Product
Product Minimum_Price
1500
Aggregate Function – Max()
Example
SELECT Max(Price) AS Maximum_Price
from Product
Product
Product Maximum_Price
8000
GROUP BY clause
Syntax
• tables: It specifies the table from where you want to retrieve records.
Example 1
Product
Product Pdt_Type Maximum_Price
Books 1500
Electronics 8000
Men 5000
Apparel
GROUP BY clause
Example 1
Product Error.
Because the select
Expression Product_Id
is missing in GROUP BY
Ensure that all of the GROUP BY columns match the SELECT clause.
having_conditions: It specifies the conditions that are applied only to the
aggregated results to restrict the groups of returned rows.
The GROUP BY clause is used in the SELECT statement for grouping the rows
by values of column or expression. For example, given groups of products in
several categories, the AVG() function returns the average price of products
in each category
THANKS