I have the following sql query that uses PIVOT. I want to be able to add the total of the M, F, and U students per grade and the total of all male and female students. Help please. Thanks
SELECT *
FROM (
SELECT
grade
, gender
FROM
STUDENTS
WHERE status = 0
AND schoolid=122)
PIVOT (
count(gender)
for (gender)
in ('M', 'F','U')
)
ORDER BY grade
The output I get now is
grade M F U
10 288 326 0
11 336 285 0
12 300 259 0
But my users want this output to be
grade M F U Total
10 288 326 0 614
11 336 285 0 621
12 300 259 0 559
Tot 924 870 0 1794