CASE statement refresher
CASE statements are useful for grouping values into different buckets based on conditions you specify. Any row that fails to satisfy any condition will fall to the ELSE statement (or show as null if no ELSE statement exists).
In this exercise, your goal is to create the segment field that buckets an athlete into one of three segments:
- Tall Female, which represents a female that is at least 175 centimeters tall.
- Tall Male, which represents a male that is at least 190 centimeters tall.
- Other
Each segment will need to reference the fields height and gender from the athletes table. Leverage CASE statements and conditional logic (such as AND/OR) to build this.
Remember that each line of a case statement looks like this:
CASE WHEN {condition} THEN {output}
Este exercício faz parte do curso
Reporting in SQL
Instruções do exercício
- Update the
CASEstatement to output three values:Tall Female,Tall Male, andOther.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
SELECT
name,
-- Output 'Tall Female', 'Tall Male', or 'Other'
CASE ____
____
____ END AS segment
FROM athletes;