SQL Select有多个求和函数的问题

时间:2014-04-23 20:08:55

标签: php mysql sql

使用MySQL数据库和PHP我有一个名为appData的表和一些数字类型的列,我需要将它们的总和作为:

SELECT projectID,
       lat,
       long,       
       powerline, 
       penstock, 
       road, 
       area, 
       expense 
FROM asppData 
WHERE active = 1;

现在,你可以看到我有powerline, penstock, road, area, expense数字类型(Km或货币),我需要将它们全部加在一起,请你告诉我如何做到这一点?

由于

1 个答案:

答案 0 :(得分:1)

SELECT projectID,
       lat,
       long,       
       sum(powerline), 
       sum(penstock), 
       sum(road), 
       sum(area), 
       sum(expense) 
FROM asppData 
WHERE active = 1
group by projectID
       lat,
       long,