Warehouse temperature sensors should report every 5 minutes. Identical (sensor_id, reading_ts) rows are duplicates. Consecutive readings at most 15 minutes apart belong to the same ONLINE period; a gap of more than 15 minutes starts a new period. Return `sensor_id`, `period_start`, `period_end`, `readings` (distinct timestamps in the period). Order by `sensor_id`, `period_start`.
| Column | Type |
|---|---|
| sensor_id | TEXT |
| reading_ts | TIMESTAMP |
| temp_c | REAL |
| sensor_id | reading_ts | temp_c |
|---|---|---|
| S1 | 2026-11-01 00:00:00 | 4.1 |
| S1 | 2026-11-01 00:05:00 | 4 |
| S1 | 2026-11-01 00:10:00 | 4.2 |
| S1 | 2026-11-01 00:40:00 | 4.4 |
| S1 | 2026-11-01 00:45:00 | 4.3 |
| S1 | 2026-11-01 01:30:00 | 4.1 |
| S2 | 2026-11-01 00:00:00 | -18 |
| S2 | 2026-11-01 00:15:00 | -18.2 |
| sensor_id | period_start | period_end | readings |
|---|---|---|---|
| S1 | 2026-11-01 00:00:00 | 2026-11-01 00:10:00 | 3 |
| S1 | 2026-11-01 00:40:00 | 2026-11-01 00:45:00 | 2 |
| S1 | 2026-11-01 01:30:00 | 2026-11-01 01:30:00 | 1 |
| S2 | 2026-11-01 00:00:00 | 2026-11-01 00:15:00 | 2 |
| S2 | 2026-11-01 00:31:00 | 2026-11-01 00:31:00 | 1 |
Solve it in the live editor on this page — run on sample data, then submit against hidden tests.
‹ App Store Year-over-Year Revenue by Category · Riders Taking a Second Trip Within 7 Days ›
{{ totalCount }} questions in the style asked at Amazon, Microsoft, Google, Meta, Flipkart and more — {{ hardPct }}% Hard. Write SQL in a real database engine in your browser, run it on sample data, then evaluate against hidden tests.
Company tags show where this type of question is commonly reported in interviews. Questions, data and solutions are written by TechTown.
{{ cur.statement }}
No submissions yet. Press Evaluate to submit your query.
{{ solutionSql }}
{{ out.error }}
You have solved your 3 free questions — nice work! Log in (free) to unlock all 150 questions, keep your streak and appear on the leaderboard.