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;
输出:
链接:https://www.learnfk.comhttps://www.learnfk.com/mariadb/mariadb-sum-function.html
来源:LearnFk无涯教程网
您可以将DISTINCT子句与SUM函数一起使用,以避免重复值求和。
示例:
SELECT SUM(DISTINCT salary) AS "Total Salary" FROM Student WHERE student_name = 'Mahesh';
输出:
链接:https://www.learnfk.comhttps://www.learnfk.com/mariadb/mariadb-sum-function.html
来源:LearnFk无涯教程网
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)