1、GROUP BY
GROUP BY 语句根据一个或多个列对结果集进行分组。
在分组的列上我们可以使用 COUNT, SUM, AVG,等函数。
语法示例:
SELECT column_name, function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;
2、WITH ROLLUP
WITH ROLLUP可以实现在分组统计数据基础上再进行相同的统计(SUM,AVG,COUNT…)。
语法示例:
SELECT column_name, function(column_num)
FROM table_name
WHERE column_name operator value
GROUP BY column_name WITH ROLLUP;