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;
Count students with even vs odd ages.
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;