0

我正在使用用户 Keevas 的示例,但提出了一个不同的问题......

select Master_Code, SUM(Jan), SUM(Feb), SUM(Mar)
 from dbo.foobar
WHERE Participating_City = 'foofoo'
GROUP BY Master_Code ORDER BY Master_Code ASC

像这样的东西:

Master_Code sum(Jan) Sum(Feb) sum(Mar)  Total
        1     4         5       4        13
        2     5         5       5        15

如何获得总值列?谢谢!

4

3 回答 3

0

这应该有效:

select Master_Code
    , SUM(Jan)
    , SUM(Feb)
    , SUM(Mar)
    , (SUM(Jan + Feb + Mar)) As Total
 from dbo.foobar
WHERE Participating_City = 'foofoo'
GROUP BY Master_Code 
ORDER BY Master_Code ASC
于 2012-08-01T16:13:12.870 回答
0

只需使用加号添加它们。

SELECT Master_Code, SUM(Jan), SUM(Feb), SUM(Mar), SUM(Jan) + SUM(Feb) + SUM(Mar) FROM...
于 2012-08-01T16:13:18.513 回答
0
select Master_Code, 
       SUM(Jan), 
       SUM(Feb),
       SUM(Mar),
       SUM(Jan+Feb+Mar) as Total
from dbo.foobar
WHERE Participating_City = 'foofoo'
GROUP BY Master_Code
ORDER BY Master_Code ASC
于 2012-08-01T16:12:03.707 回答