Skip
Arish's avatar

141. Practice - CASE Expression


Exercise: Age Category

Categorize ages: Child (<13), Teen (13-17), Adult (18+).

Solution

sql
1SELECT name, age,
2  CASE
3    WHEN age < 13 THEN 'Child'
4    WHEN age <= 17 THEN 'Teen'
5    ELSE 'Adult'
6  END AS age_group
7FROM students;