Back to Practice
#0382
Latest Non-NULL Measurement Date
MediumSQL24 min20 XP
Problem
Return sensor_id and last_measurement_date for non-NULL readings.
Why This Matters
SQL interviews usually test whether you can turn a business question into the right rows, grouping level, join type, and edge-case behavior.
Schema
readings(sensor_id INTEGER, reading_date TEXT, value REAL)
Examples
Example 1
Inputsensor 2 has only NULL readings
Outputsensor 1 only
WHERE value IS NOT NULL removes missing measurements before MAX.
Constraints
- Return only the requested columns.
- Use deterministic ORDER BY when multiple rows are returned.
- Assume SQLite-compatible SQL unless the prompt states otherwise.
CodeSQL
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core SQL case
Inputsensor 2 has only NULL readings
Expected[[1,"2026-01-03"]]
WHERE value IS NOT NULL removes missing measurements before MAX.
Hidden Test Categories
Empty or missing matchesDuplicate rows or tiesNULL values where the pattern commonly breaks