I am experimenting with using Rollup, and wanted to find out if there's a way to achieve this without using a subquery, CTE or Temp Table. Here's my code:
select coalesce(Answer,case Grouping_ID(Answer) when 1 then 'Total' end) as Answer
, Count(*) as CSAT_Count
, Case Answer
when 'Average' then 2*count(*)
when 'Outstanding' then 3*Count(*)
when 'Unsatisfactory' then 1*Count(*)
end as CSAT_Score
from CSAT_Table
Where Empl_ID = 98
Group by Answer
with rollup
Here's the result:
Answer CSAT_Count CSAT_Score
----------------------------------------------
Average 13 26
Outstanding 126 378
Unstatisfactory 6 6
Total 145 NULL
I'd like to have the NULL returning in CSAT_Score reflect the sum of the scores, but I'm thinking because the score is relying on COUNT(*) to be calculated, I can't get Rollup to do this for me, since I can't group by an aggregate.
Like I said above, I know a subquery, CTE or Temp table storing the result of the count would work, but since I'm new to using Rollup, I wanted to see if there was something else I could do with that function to make this work.
Thanks