Get startedGet started for free

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}

This exercise is part of the course

Reporting in SQL

View Course

Exercise instructions

  • Update the CASE statement to output three values: Tall Female, Tall Male, and Other.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT 
	name,
    -- Output 'Tall Female', 'Tall Male', or 'Other'
	CASE ____
    ____
    ____ END AS segment
FROM athletes;
Edit and Run Code