Page 112 - Computer Software Application TP - Volume 1
P. 112
COMPUTER SOFTWARE APPLICATION - CITS
TASK 4 : Using GROUP BY:
The MYSQL GROUP BY Clause is used to collect data from multiple records and group the result by one or more
column. It is generally used in a SELECT statement.
SELECT product, SUM(amount) as total sales
FROM sales
GROUP BY product;
This query selects the product and the total sales (SUM(amount)) for each product from the sales table, grouped
by the product column.
You can use other aggregate functions like COUNT, AVG, MIN, MAX, etc., depending on your requirements.
1 SELECT product, COUNT(*) as total orders, AVG(amount) as avg sales
FROM sales
GROUP BY product;
97
CITS : IT & ITES - Computer Software Application - Exercise 29 CITS : IT & ITES - Computer Software Application - Exercise 29