Alright. We will now show you two other ways of using
CASE WHEN with
GROUP BY statements and aggregate functions. Take a look at the following example:
CASE WHEN COUNT(pay_date) > 5
THEN 'high' ELSE 'low' END
GROUP BY pay_date;
The above query will group all applications according to the date where the payment was made. Then, it counts the number of payments on each date. Up to this point, it's pretty standard, right? But look what happens next: we can use
CASE WHEN to show a comment on the values of the aggregate function. If it's more than 5, we'll say that the number is 'high'. Otherwise, we'll show 'low'.