SELECT
CASE WHEN GROUPING(student) = 1
THEN '合计'
ELSE student END,
CASE WHEN GROUPING(student) <> 1 and GROUPING(course) = 1
THEN '小计'
ELSE course END,
sum(score.score)
FROM score
GROUP BY ROLLUP (student, course)
ORDER BY GROUPING(student) DESC ,student DESC, GROUPING(course) DESC ,course DESC;