Premium problem35. Odd vs Even Readings Per Day

Medium Locked

measurements(measurement_id, measured_at, value)

Within each calendar day, order the measurements by measured_at then measurement_id, and sum the values at odd positions and even positions separately.

Return measurement_date, odd_sum and even_sum, ordered by date.

Position is per day and restarts each morning, so a day with three readings has positions 1, 2, 3 regardless of what came before.

Tables

measurements

measurement_id  measured_at          value
--------------  -------------------  ------
1               2026-06-01 08:00:00  10.00
3               2026-06-01 09:00:00  20.00
2               2026-06-01 09:00:00  30.00
4               2026-06-02 08:00:00  100.00
5               2026-06-02 09:00:00  200.00

Expected result

measurement_date  odd_sum  even_sum
----------------  -------  --------
2026-06-01        30.00    30.00
2026-06-02        100.00   200.00

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query