📅  最后修改于: 2020-11-29 05:47:36             🧑  作者: Mango
MariaDB SUM函数用于返回表达式的求和值。
句法:
SELECT SUM(aggregate_expression)
FROM tables
[WHERE conditions];
例:
计算“ student_id”大于1的“ Student”表的总薪水。
SELECT SUM(salary) AS "Total Salary"
FROM Student
WHERE student_id > 1;
输出:
您可以将DISTINCT子句与SUM函数一起使用,以避免重复值求和。
例:
SELECT SUM(DISTINCT salary) AS "Total Salary"
FROM Student
WHERE student_name = 'Mahesh';
输出: