GROUP BY: SELECT dept,COUNT(*) c FROM emp GROUP BY dept; : Aggregate rows sharing same attribute
HAVING: SELECT dept,COUNT(*) c FROM emp GROUP BY dept HAVING c>5; : Filter groups based on
aggregate conditions
COUNT(): SELECT COUNT(*) FROM t; : Return number of rows or non NULL values
SUM() / AVG() / MIN() / MAX(): SELECT AVG(salary) FROM emp; : Compute total, average, minimum, or
maximum of numeric columns
GROUP_CONCAT(): SELECT GROUP_CONCAT(name ORDER BY name) FROM products; : Concatenate strings from grouped rows.
ROLLUP: GROUP BY year,quarter WITH ROLLUP; : Generate subtotals along hierarchy levels
CUBE: GROUP BY CUBE(year,quarter); : Produce subtotals for all combinations of grouping columns
GROUPING SETS: GROUP BY GROUPING SETS ((year,quarter),(year),()); : Specify custom combinations
for aggregation
ANY_VALUE(): SELECT year,ANY_VALUE(product) FROM sales GROUP BY year; : Return arbitrary
non aggregate column when only_full_group_by is on
STDDEV() / VARIANCE(): SELECT STDDEV(population) FROM cities; : Compute statistical dispersion
measures
HAVING: SELECT dept,COUNT(*) c FROM emp GROUP BY dept HAVING c>5; : Filter groups based on
aggregate conditions
COUNT(): SELECT COUNT(*) FROM t; : Return number of rows or non NULL values
SUM() / AVG() / MIN() / MAX(): SELECT AVG(salary) FROM emp; : Compute total, average, minimum, or
maximum of numeric columns
GROUP_CONCAT(): SELECT GROUP_CONCAT(name ORDER BY name) FROM products; : Concatenate strings from grouped rows.
ROLLUP: GROUP BY year,quarter WITH ROLLUP; : Generate subtotals along hierarchy levels
CUBE: GROUP BY CUBE(year,quarter); : Produce subtotals for all combinations of grouping columns
GROUPING SETS: GROUP BY GROUPING SETS ((year,quarter),(year),()); : Specify custom combinations
for aggregation
ANY_VALUE(): SELECT year,ANY_VALUE(product) FROM sales GROUP BY year; : Return arbitrary
non aggregate column when only_full_group_by is on
STDDEV() / VARIANCE(): SELECT STDDEV(population) FROM cities; : Compute statistical dispersion
measures