SQL GROUP BY

GROUP BY 按列分组,使聚合函数对每组各算一个值;SELECT 里的非聚合列必须出现在 GROUP BY 中。

Beginner
Key PointsSQL,GROUP BY,分组,聚合

讲解

GROUP BY 按列分组,使聚合函数对每组各算一个值;SELECT 里的非聚合列必须出现在 GROUP BY 中。

示例

SQL
SELECT site_id, SUM(count) AS total
FROM access_log
GROUP BY site_id;
Output
site_id  total
-------  -----
1        45
2        100
3        230

Friends & Partners