SQL SUM()

SUM() 返回数值列总和(忽略 NULL),常配合 GROUP BY 做分组汇总。

Beginner
Key PointsSQL,SUM,求和

讲解

SUM() 返回数值列总和(忽略 NULL),常配合 GROUP BY 做分组汇总。

示例

SQL
SELECT SUM(count) AS total FROM access_log;

SELECT site_id, SUM(count) AS total
FROM access_log GROUP BY site_id;
Output
total
-----
375

site_id  total
-------  -----
1        45
2        100
3        230

Friends & Partners