Correct, nice! Now, let's combine
CASE WHEN with some aggregate functions.
You've learned the function
SUM(), the constructions
CASE WHEN and you know that
CASE WHEN can return numbers. Now, let's combine all of this information to make a very convenient query which can count various groups of rows at the same time. Take a look:
WHEN scholarship IS TRUE THEN place_limit
END) AS scholarship_places,
WHEN scholarship IS FALSE THEN place_limit
END) AS no_scholarship_places
The above query counts two
SUMs: the number of places in all courses which offer scholarship and the number of places in those which don't.
SUM, we put a
CASE WHEN statement. When the value in the column
scholarship is true, then we add the value from the column
place_limit to the sum called
scholarship_places. Otherwise, we add 0. The other
SUM is calculated in the same way.