Odd and Even Page Counts per Shelving Day
Problem
A library logs every book returned to the stacks in the table `returns_log`. Each row has a `return_id`, the book's `page_count` (a whole number), and the `shelved_on` date the book was reshelved.
For each shelving day, report two sums: `odd_pages` — the total of all `page_count` values that are odd — and `even_pages` — the total of all `page_count` values that are even. A day that has no odd (or no even) books should still report that sum as 0 rather than NULL. Return one row per `shelved_on` date and order the result by `shelved_on`.
Tables
Example rows — the live problem includes the full dataset.
| return_id | page_count | shelved_on |
|---|---|---|
| 1 | 150 | 2024-09-01 |
| 2 | 201 | 2024-09-01 |
| 3 | 88 | 2024-09-01 |
Expected output
Your answer should return 3 rows with the columns shelved_on, odd_pages, even_pages.
Starter code (SQL)
SELECT *
FROM returns_log;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock