九、分组 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;
使用 WITH ROLLUP
WITH ROLLUP 可以实现在分组统计数据基础上再进行相同的统计(SUM,AVG,COUNT…)。
如:
SELECT nickname, Avg(age) as avgage FROM pupil GROUP BY nickname WITH ROLLUP;
标签:GROUP,name,column,SUM,ROLLUP,分组 来源: https://www.cnblogs.com/epiphany8/p/16369431.html