Instruction
Okay then, it's time to revise the most important aspects of CASE WHEN.
- A simple
CASE WHENhas the following syntax:CASE column_name WHEN value1 THEN text1 WHEN value2 THEN text2 ... ELSE text_else END
- A searched
CASE WHENhas the following syntax:CASE WHEN condition1 THEN text1 WHEN condition2 THEN text2 ... ELSE text_else END
- The
ELSEpart is optional. - Remember to put the
ENDclause at the end. - You can use
CASE WHENwithSUMto count multiple values in a single query:SUM(CASE WHEN x THEN 1 ELSE 0 END)
- Similarly, you can use
CASE WHENwithCOUNTto count multiple values in a single query:COUNT(CASE WHEN x THEN column END)
Exercise
Are you ready for some practice? Let's find out!



