1.求某列指定字段之和(一列多行):sum(字段名)
select t.Status,sum(t.Amount)from table t
where t.CreateTime between '2018-05-29 00:00:00' and '2018-05-29 23:59:59'
group by t.Status;
2.求几个字段之和(一行多列)
SELECT t.列1 + t.列2 + t.列3 AS Total FROM table t
WHERE t.time = '2018-05-29 00:00:00';
或
SELECT SUM(t.列1 + t.列2 + t.列3) AS Total FROM table t
WHERE t.time = '2018-05-29 00:00:00';
网友评论