GROUP BY - multiple columns

GROUP BY over multiple columns

Let’s say we define status for every student who gets marks over 33 as Passed and others as Failed. Write a query to show count of students for all unique combinations of grade and status, where grade is present

The headers for grade, status and count of students should be grade, status and count respectively.

The result should look something like this.

grade status count
1 Passed 2
1 Failed 1
2 Passed 3


  1. You can use CASE..WHEN..THEN..ELSE..END syntax to get conditional data from a row and wrap its result with an alias.

  2. An alias can also be used in a GROUP BY clause.