Skip
Arish's avatar

156. Practice - Computed GROUP BY


Exercise: Group by Even/Odd

Count students with even vs odd ages.

Solution

sql
1SELECT 
2  CASE WHEN age % 2 = 0 THEN 'Even' ELSE 'Odd' END AS age_type,
3  COUNT(*) AS count
4FROM students
5GROUP BY age % 2;