How to return varchar string instead of null with rollup?
When I run this query:
select
First_Name,
sum(a) a,
sum(b) b,
开发者_如何学C sum(c) c
from someTable
group by First_Name with rollup
the first column First_Name
and the last row (total row) shows a NULL (since it can't be summed), I want to show a custom string value instead of null. I know I can use isnull
or a case
here, but I want only the rolled up row to be affected.
Thanks!
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
CASE WHEN GROUPING(First_Name) = 1 THEN 'FOO' ELSE First_Name END AS First_Name
精彩评论