WITH
temp
AS
( SELECT course,
gender,
COUNT (CASE
WHEN grade IN ('A+',
'A-',
'B',
'B+',
'B-',
'C',
'C+',
'F')
THEN
'Total Enrolled with grades'
END) AS total_enrolled,
COUNT (CASE
WHEN grade IN ('A+',
'A-',
'B',
'B+',
'B-',
'C',
'C+')
THEN
'Pass'
END) AS total_pass
FROM result
GROUP BY course, gender)
SELECT course,
gender,
total_enrolled,
total_pass,
--
(total_pass / total_enrolled) * 100 AS fifth_column
FROM temp
ORDER BY course
或者,你可以重新输入
CASE
顺便说一句,就像他们在报纸上说的
2001:太空漫游