Adding Total row

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

With CTE as (
select 12 ID, 'OF' [Type], 500 Sqft
union all
select 14, 'IN', 1294
union all
select 99, 'OF', 12042
union all
select 24, 'ME', 92043
union all
select 15, 'IN', 13945
union all
select 16, 'OW', 2650
)
select CASE WHEN GROUPING_ID(Type) = 1 THEN 'TOTAL' ELSE Type END [Type],
Sum(Sqft) Sqft, GROUPING_ID(Type) [Grouping]
from CTE
group by GROUPING SETS ((Type),())

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results