当我运行此查询时:
select
First_Name,
sum(a) a,
sum(b) b,
sum(c) c
from someTable
group by First_Name with rollup
第一列First_Name
和最后一行(总行)显示NULL(因为它无法求和),我想显示一个自定义字符串值而不是null。我知道我可以在这里使用isnull
或case
,但我只希望卷起的行受到影响。
谢谢!
答案 0 :(得分:3)
SELECT CASE WHEN GROUPING_ID(First_Name) = 1 THEN 'Total' ELSE First_Name END,
SUM(a),
SUM(b),
SUM(c)
FROM data
GROUP BY
First_Name WITH ROLLUP
答案 1 :(得分:1)
CASE WHEN GROUPING(First_Name) = 1 THEN 'FOO' ELSE First_Name END AS First_Name