我在我的SQL查询中使用with rollup
。我没有获得汇总的别名。
我的SQL是
SELECT [Column1],
sum([Column2])
FROM Tablea
GROUP BY [Column2] WITH ROLLUP
返回
s 8
t 8
j 8
null 24
如何替换总行中的NULL
?
答案 0 :(得分:18)
您可以在CASE
表达式中使用GROUPING
函数。
SELECT CASE
WHEN GROUPING([Column1]) = 1 THEN 'Total'
ELSE [Column1]
END [Column1],
sum([Column2])
FROM Tablea
GROUP BY [Column1] WITH ROLLUP
答案 1 :(得分:1)
select
isnull([column1],'rollup'),
sum([column2] )
from tableA
group by [column1]
WITH ROLLUP
答案 2 :(得分:-4)
SELECT ifnull([column1],'total'),
sum([Column2])
FROM Tablea
GROUP BY [Column2] WITH ROLLUP