Introduction
Simple CASE WHEN
Searched CASE WHEN
CASE WHEN with aggregates
15. CASE WHEN with SUM continued
CASE WHEN with GROUP BY
Revision

Instruction

Great! The use of CASE WHEN together with SUM is actually so important that we should do one more exercise here. Are you ready?

Exercise

Count the number of candidates with preferred_contact set to:

  • mobile (mobile_sum),
  • e-mail (email_sum),
  • mail (mail_sum),
  • or with NULL (null_sum).

Only count candidates whose score in maths and score in language is greater than or equal to 30.

 

Stuck? Here's a hint!

Start with

SELECT
  SUM(CASE WHEN preferred_contact = 'mobile' THEN 1 ELSE 0 END)
  AS mobile_sum

and continue in the same way.

 

Console

Code editor

Result

TableConsole