Skip
Arish's avatar

121. Detecting Even and Odd Numbers


Even and Odd

sql
1-- Even numbers (divisible by 2)
2SELECT * FROM students WHERE id % 2 = 0;
3
4-- Odd numbers
5SELECT * FROM students WHERE id % 2 = 1;

Example

sql
1SELECT name, age,
2  CASE WHEN age % 2 = 0 THEN 'Even' ELSE 'Odd' END AS age_type
3FROM students;