2011-03-23 98 views
2

當我運行此查詢:如何返回varchar字符串而不是null與彙總?

select 
    First_Name, 
    sum(a) a, 
    sum(b) b, 
    sum(c) c 
from someTable 
group by First_Name with rollup 

第一列First_Name和最後一行(總行)是NULL(因爲它不能概括),我想顯示自定義字符串值,而不是空值。我知道我可以在這裏使用isnullcase,但我只想要捲起的行受到影響。

謝謝!

回答

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 
+0

謝謝你的偉大工程 – 2011-04-06 22:43:21

1

CASE WHEN GROUPING(First_Name) = 1 THEN 'FOO' ELSE First_Name END AS First_Name

相關問題