我有这个查询:
DECLARE @t TABLE(NAME NVARCHAR(MAX),datee date,val money)
insert INTO @t SELECT 'a','2012-01-02',100
insert INTO @t SELECT 'a','2012-01-02',100
insert INTO @t SELECT 'a','2012-01-03',100
insert INTO @t SELECT 'a','2012-01-05',100
insert INTO @t SELECT 'b','2012-01-06',200
insert INTO @t SELECT 'b','2012-01-07',200
insert INTO @t SELECT 'd','2012-01-07',400
insert INTO @t SELECT 'e','2012-01-09',500
insert INTO @t SELECT 'f','2012-01-12',600
SELECT Name,datee,SUM (val)
from @t GROUP BY NAME ,datee
目前的结果是:
但我需要sum
在最后添加。所以我尝试了汇总:
SELECT Name,datee,SUM (val)
from @t GROUP BY NAME ,datee with ROLLUP
但我只需要最后一个总和行。我不需要内报告 sum's
那么如何才能得到想要的结果呢?
(我不能更改 group by
子句,因为其他人也需要它,我只想在最后加上/不加总和)。