GROUP BY Expression

The GROUP BY expression is used to group records with the same values, such as “show the number of employees in each department.” GROUP BY is used in conjunction with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result set by one or more columns. The HAVING expression is used to filter the aggregated set based on the aggregate value.

Formula:

SELECT column1
, column2
, COUNT(column3)
FROM Table1
WHERE condition1
GROUP BY  column1, column2
HAVING COUNT(column3) > value
ORDER BY 1, 2;

Important! If additional columns appear in a query containing an aggregate function, you must always use the GROUP BY function.

Interesting article? Share further!

Leave A Comment