Peak Telemetry Readings and Warehouse Modeling
Medium · Data Manipulation (SQL/Python) · Data Engineer · Technical Screen
Problem Statement
A data engineering technical screen covers three topics across SQL set logic, windowed analytics, and dimensional modeling. The automated SQL runner grades Part 2, while Parts 1 and 3 are open-ended discussion prompts you should also be ready to explain.
Part 1 — Set Operations and Anti-Joins
Suppose a warehouse holds two tables, active_sensors and backup_sensors, and each table has a nullable integer column sensor_id.
- Compare
UNIONandUNION ALLin terms of execution cost, memory usage, and data movement. When should you choose each operator in a large analytical warehouse? - Write a SQL query that outputs every non-
NULLsensor_idpresent inactive_sensorsthat does not appear inbackup_sensors. Make sure your query stays accurate even when either table containsNULLvalues.
Part 2 — Top-3 Readings per Sensor (Graded SQL Query)
Using the sensor_readings table defined below, write a SQL query that returns up to the 3 largest non-NULL reading_value measurements recorded for each sensor_id during the preceding 24 hours.
Apply these exact evaluation rules:
- Fix the current reference time at
2023-10-01 12:00:00. A reading falls inside the 24-hour window when itstimestamplies between2023-09-30 12:00:00and2023-10-01 12:00:00, inclusive of both endpoints. - Discard any row where
reading_valueisNULL. - For each
sensor_id, rank valid in-window rows from highestreading_valueto lowest. When two rows for the same sensor have identicalreading_valuenumbers, favor the row with the latertimestamp. - Output at most 3 rows per
sensor_id(even if exact duplicate rows exist). If a sensor has only 1 or 2 qualifying rows, output all of them; if it has none, omit that sensor. - Return columns
sensor_id,reading_value, andtimestampin any row order.
Part 3 — Telemetry Warehouse Modeling
You are designing the analytical storage layer for high-frequency device telemetry.
- Contrast a fact table with a dimension table inside a star schema.
- Suppose a physical sensor receives a field servicing upgrade that changes descriptive attributes (such as mounting site or hardware vendor) while keeping the same
sensor_id. Explain how to track full historical accuracy using a Type 2 Slowly Changing Dimension (SCD Type 2).
Input Schema
sensor_readings
| Column | Type | Description |
|---|---|---|
sensor_id |
INTEGER |
Identifier of the telemetry device |
reading_value |
DOUBLE |
Recorded numeric measurement (may be NULL) |
timestamp |
TIMESTAMP |
Measurement time formatted as 'YYYY-MM-DD HH:MM:SS' |
Examples
Example 1
Input (sensor_readings):
| sensor_id | reading_value | timestamp |
|---|---|---|
| 10 | 88.0 | 2023-09-29 18:00:00 |
| 10 | NULL | 2023-10-01 11:30:00 |
| 10 | 74.5 | 2023-10-01 08:15:00 |
| 10 | 71.0 | 2023-09-30 19:00:00 |
| 10 | 71.0 | 2023-10-01 09:45:00 |
| 10 | 68.2 | 2023-10-01 10:20:00 |
| 20 | 42.8 | 2023-09-30 12:00:00 |
| 20 | 45.3 | 2023-10-01 12:00:00 |
Expected Output:
| sensor_id | reading_value | timestamp |
|---|---|---|
| 10 | 74.5 | 2023-10-01 08:15:00 |
| 10 | 71.0 | 2023-10-01 09:45:00 |
| 10 | 71.0 | 2023-09-30 19:00:00 |
| 20 | 45.3 | 2023-10-01 12:00:00 |
| 20 | 42.8 | 2023-09-30 12:00:00 |
Walk-through: For sensor 10, 88.0 happened prior to 2023-09-30 12:00:00 and the 11:30:00 row is NULL, so both are excluded before ranking; of the remaining four valid measurements (74.5, 71.0, 71.0, 68.2), the top three are kept and 68.2 is dropped. For sensor 20, both timestamps sit right on the inclusive 24-hour boundaries, and since there are only two valid rows, both are returned.
Example 2
Input (sensor_readings):
| sensor_id | reading_value | timestamp |
|---|---|---|
| 30 | 60.0 | 2023-10-01 06:00:00 |
| 30 | 55.0 | 2023-10-01 07:00:00 |
| 30 | 55.0 | 2023-10-01 09:30:00 |
| 30 | 55.0 | 2023-10-01 08:15:00 |
| 40 | 91.0 | 2023-10-01 12:00:01 |
Expected Output:
| sensor_id | reading_value | timestamp |
|---|---|---|
| 30 | 60.0 | 2023-10-01 06:00:00 |
| 30 | 55.0 | 2023-10-01 09:30:00 |
| 30 | 55.0 | 2023-10-01 08:15:00 |
Walk-through: Sensor 30 has a three-way tie at 55.0 behind 60.0; ordering tied values by timestamp descending retains the 09:30:00 and 08:15:00 rows while dropping 07:00:00. Sensor 40's sole measurement is one second past 2023-10-01 12:00:00, so sensor 40 produces zero rows.
Constraints
timestampsare formatted as ISO strings'YYYY-MM-DD HH:MM:SS'in the same UTC clock as the reference timestamp'2023-10-01 12:00:00'.reading_valuemay be negative, zero, positive, orNULL.sensor_readingsmay be empty and may contain duplicate(sensor_id, reading_value, timestamp)rows; eachsensor_idmust never appear more than 3 times in the result.- Result rows may be returned in any order, with exact column names
sensor_id,reading_value,timestamp.
Step-by-step walkthrough
Understand the three parts and the graded query
This interview prompt covers three core data engineering areas: SQL set operations (Part 1), top-N-per-group analytics (Part 2), and dimensional warehouse modeling (Part 3).
The automated judge runs Part 2 against
sensor_readings(sensor_id, reading_value, timestamp). Let us build that query step by step first, and then walk through crisp, interview-ready answers for Parts 1 and 3 right before the final submission.Here are the exact rules for Part 2:
- "Now" is fixed at
2023-10-01 12:00:00, so the last 24 hours is the inclusive window[2023-09-30 12:00:00, 2023-10-01 12:00:00]. - Rows where
reading_valueisNULLmust be ignored. - Return at most 3 rows per
sensor_idwith columnssensor_id, reading_value, timestamp. - If two readings for the same sensor have the same
reading_value, prefer the more recenttimestamp. - If a sensor has only 1 or 2 valid readings in the window, return all of them; if it has 0, return none. Row order does not matter.
- "Now" is fixed at
Why GROUP BY and LIMIT fall short
Beginners usually reach for
GROUP BYorLIMIT 3first, and both hit a wall:-- Wrong: collapses each sensor down to 1 row instead of keeping its top 3 SELECT sensor_id, MAX(reading_value) FROM sensor_readings GROUP BY sensor_id; -- Wrong: keeps 3 rows across the ENTIRE table instead of 3 per sensor SELECT sensor_id, reading_value, timestamp FROM sensor_readings ORDER BY reading_value DESC LIMIT 3;What we actually want is to keep every individual reading row intact while attaching a per-sensor rank (
1,2,3, ...) to each row. That is the exact job of a window function—a SQL calculation (OVER (...)) that looks across a related group of rows and adds a computed column without collapsing rows together.To keep our query easy to read, we will also organize it with Common Table Expressions (CTEs)—named temporary steps introduced with
WITH step_name AS (...)that read from top to bottom like variables in code.Filter the 24-hour window and NULLs before ranking
The order of operations is crucial: we must discard out-of-window rows and
NULLvalues before numbering each sensor's readings.Why? Suppose sensor
10recorded88.0on September 29 and74.5today (as in Example 1). If we numbered all historical rows first,88.0would take rank 1 and74.5would drop to rank 2; filtering to the last 24 hours afterward would throw away rank 1 and leave sensor10with only two rows instead of three!Raw rows for sensor 10 (Example 1): (10, 88.0, '2023-09-29 18:00:00') --> outside 24h window -> drop first! (10, NULL, '2023-10-01 11:30:00') --> NULL reading -> drop first! (10, 74.5, '2023-10-01 08:15:00') --> valid -> survives into ranking (10, 71.0, '2023-10-01 09:45:00') --> valid -> survives into rankingFiltering
reading_value IS NOT NULLinWHEREalso protects us across SQL engines: SQLite treatsNULLas smaller than any number (soORDER BY reading_value DESCputsNULLlast), whereas PostgreSQL treatsNULLas larger than any number by default and would putNULLat rank 1!Because ISO timestamps formatted as
YYYY-MM-DD HH:MM:SSsort chronologically from left to right,>=and<=include both endpoints cleanly:WITH recent_readings AS ( -- Step 1: Filter out NULL values and out-of-window timestamps BEFORE ranking -- so old spikes or missing readings can never consume a sensor's top-3 slots. -- Both endpoints of [2023-09-30 12:00:00, 2023-10-01 12:00:00] are inclusive. SELECT sensor_id, reading_value, timestamp FROM sensor_readings WHERE reading_value IS NOT NULL AND timestamp >= '2023-09-30 12:00:00' AND timestamp <= '2023-10-01 12:00:00' ),Number each sensor's readings with ROW_NUMBER
SQL offers three ranking window functions:
ROW_NUMBER(),RANK(), andDENSE_RANK(). Let us trace all three on sensor30from Example 2 (60.0and a three-way tie at55.0) to see why the choice matters:reading_value | timestamp | ROW_NUMBER | RANK | DENSE_RANK --------------+---------------------+------------+------+----------- 60.0 | 2023-10-01 06:00:00 | 1 | 1 | 1 55.0 | 2023-10-01 09:30:00 | 2 | 2 | 2 55.0 | 2023-10-01 08:15:00 | 3 | 2 | 2 55.0 | 2023-10-01 07:00:00 | 4 | 2 | 2If we filter on
rank <= 3,RANK()andDENSE_RANK()onreading_valuereturn all 4 rows, violating "at most 3 rows per sensor" (even if you addtimestamptoORDER BY, two exact duplicate telemetry packets with the same value and timestamp would still tie inRANK()and push the count past 3).ROW_NUMBER()always assigns distinct integers1, 2, 3, 4, guaranteeing at most 3 rows per sensor.Inside
OVER (...): -PARTITION BY sensor_idsplits rows into separate buckets—one per sensor—and restarts numbering at1for every sensor. -ORDER BY reading_value DESC, timestamp DESCputs the highest values first and breaks ties in favor of the newest timestamp.ranked_readings AS ( -- Step 2: Assign 1, 2, 3, ... separately inside each sensor_id group. -- ROW_NUMBER (unlike RANK or DENSE_RANK) guarantees at most 3 rows even on exact ties, -- and timestamp DESC breaks equal reading_value ties in favor of the newer reading. SELECT sensor_id, reading_value, timestamp, ROW_NUMBER() OVER ( PARTITION BY sensor_id ORDER BY reading_value DESC, timestamp DESC ) AS row_num FROM recent_readings )Keep the top three in the outer SELECT and trace Example 1
Why can we not write
WHERE row_num <= 3directly insideranked_readings? Because SQL's logical execution order runsWHEREbeforeSELECTcomputes window functions—at the momentWHEREruns,row_numdoes not exist yet! Queryingranked_readingsfrom an outerSELECTlets us filterWHERE row_num <= 3and project only the three requested columns (leavingrow_numout of the final output).Let us trace Example 1 from start to finish:
After dropping (10, 88.0, '2023-09-29 18:00:00') and (10, NULL, '2023-10-01 11:30:00'), 6 rows survive inside [2023-09-30 12:00:00, 2023-10-01 12:00:00]: sensor_id | reading_value | timestamp | row_num | kept (row_num <= 3)? ----------+---------------+---------------------+---------+--------------------- 10 | 74.5 | 2023-10-01 08:15:00 | 1 | yes 10 | 71.0 | 2023-10-01 09:45:00 | 2 | yes (newer 71.0 first) 10 | 71.0 | 2023-09-30 19:00:00 | 3 | yes 10 | 68.2 | 2023-10-01 10:20:00 | 4 | no 20 | 45.3 | 2023-10-01 12:00:00 | 1 | yes 20 | 42.8 | 2023-09-30 12:00:00 | 2 | yesSensor
10keeps its 3 highest valid readings (74.5and both71.0rows, dropping68.2) and sensor20keeps both of its boundary readings, returning 5 rows total.Part 1: UNION vs UNION ALL and NULL-safe anti-joins
In a live technical screen, you will also answer Part 1 verbally or on the whiteboard:
-
UNIONvsUNION ALL:UNION ALLsimply stacks the rows of the second query underneath the first in a single streaming pass with zero deduplication overhead.UNIONstacks the rows and eliminates duplicates across (and within) both inputs, which forces the warehouse to build a giant hash table or sort the entire combined dataset—often spilling to disk and shuffling rows across network nodes.- Rule of thumb: Default to
UNION ALLwhenever inputs come from separate partitions/sources or when duplicates are valid event occurrences; useUNIONonly when you genuinely need set deduplication.
-
Active sensors missing from
backup_sensors(NULL-safe anti-join): An anti-join keeps rows from one table that have no matching row in another table. AvoidWHERE sensor_id NOT IN (SELECT sensor_id FROM backup_sensors)! Under SQL's three-valued logic (TRUE,FALSE,UNKNOWN), ifbackup_sensorscontains even a singleNULL,1 NOT IN (2, NULL)expands to1 <> 2 AND 1 <> NULL, which evaluates toTRUE AND UNKNOWN=UNKNOWN, causingNOT INto return zero rows.Instead, use
NOT EXISTSand handleNULLsensor IDs inactive_sensorsexplicitly:
active_sensors: [1, 2, 2, 3, NULL] backup_sensors: [2, NULL] - a.sensor_id = NULL -> filtered out explicitly by a.sensor_id IS NOT NULL - a.sensor_id = 2 -> matches b.sensor_id = 2 -> EXISTS is TRUE -> excluded - a.sensor_id = 1, 3 -> no row satisfies b.sensor_id = a.sensor_id -> included!SELECT DISTINCT a.sensor_id FROM active_sensors AS a WHERE a.sensor_id IS NOT NULL AND NOT EXISTS ( SELECT 1 FROM backup_sensors AS b WHERE b.sensor_id = a.sensor_id );-
Part 3: Star schema and Slowly Changing Dimension Type 2
For Part 3's telemetry warehouse design:
-
Fact table vs Dimension table in a Star Schema: A star schema organizes a warehouse into one central fact table joined directly to surrounding dimension tables:
- Fact table (
fct_sensor_readings): Stores high-frequency numeric measurements or events—one row per sensor reading, holding foreign keys and numbers (reading_value). Narrow, append-only, and billions of rows long. - Dimension table (
dim_sensor): Stores descriptive context used forWHEREfilters andGROUP BYlabels—location, manufacturer, firmware, install date. Wide, much smaller, and updated infrequently.
- Fact table (
-
Tracking a sensor overhaul with Slowly Changing Dimension Type 2 (SCD Type 2): If sensor
101moves from"Roof A"to"Vault B"at2023-10-01 08:00:00without changingsensor_id, overwriting its row would wrongly make last month's roof readings look like vault readings! SCD Type 2 preserves history by storing one row per version of the sensor, each with its own warehouse-generated surrogate key (sensor_key) and half-open validity interval[valid_from, valid_to):
dim_sensor after overhaul at 2023-10-01 08:00:00: sensor_key | sensor_id | location | manufacturer | valid_from | valid_to | is_current -----------+-----------+----------+--------------+---------------------+---------------------+----------- 5001 | 101 | Roof A | Acme | 2023-01-01 00:00:00 | 2023-10-01 08:00:00 | false 5002 | 101 | Vault B | OmniCorp | 2023-10-01 08:00:00 | NULL | trueEach reading joins to the version active at its event
timestampviad.sensor_id = r.sensor_id AND d.valid_from <= r.timestamp AND (d.valid_to IS NULL OR r.timestamp < d.valid_to)(or resolvessensor_keyduring ETL ingestion), keeping historical attribution 100% accurate.-
Complete SQL query
Here is the complete Part 2 query ready for the SQLite judge:
WITH recent_readings AS ( -- Step 1: Filter out NULL values and out-of-window timestamps BEFORE ranking -- so old spikes or missing readings can never consume a sensor's top-3 slots. -- Both endpoints of [2023-09-30 12:00:00, 2023-10-01 12:00:00] are inclusive. SELECT sensor_id, reading_value, timestamp FROM sensor_readings WHERE reading_value IS NOT NULL AND timestamp >= '2023-09-30 12:00:00' AND timestamp <= '2023-10-01 12:00:00' ), ranked_readings AS ( -- Step 2: Assign 1, 2, 3, ... separately inside each sensor_id group. -- ROW_NUMBER (unlike RANK or DENSE_RANK) guarantees at most 3 rows even on exact ties, -- and timestamp DESC breaks equal reading_value ties in favor of the newer reading. SELECT sensor_id, reading_value, timestamp, ROW_NUMBER() OVER ( PARTITION BY sensor_id ORDER BY reading_value DESC, timestamp DESC ) AS row_num FROM recent_readings ) -- Step 3: Filter on row_num in the outer query because SQL evaluates WHERE before window functions. SELECT sensor_id, reading_value, timestamp FROM ranked_readings WHERE row_num <= 3✅ Submit now — all tests should pass.
Intuition & how it works
Think of awarding top-3 ribbons across different age divisions at a track meet. First, officials cross off anyone whose time was not recorded (NULL) or who ran yesterday instead of today (outside the 24-hour window). Next, each division lines up on its own from best score to worst—with ties broken in favor of whoever ran most recently—and receives numbered tags 1, 2, 3, 4, ... starting fresh at 1 in every division. Finally, anyone holding tag 1, 2, or 3 steps onto the podium.
The obvious beginner attempts fail because standard SQL tools operate at the wrong granularity. GROUP BY sensor_id collapses all of a sensor's readings into a single summary row, losing 2nd and 3rd place, while ORDER BY reading_value DESC LIMIT 3 applies one global cutoff across the entire table instead of 3 per sensor. Using RANK() instead of ROW_NUMBER() also breaks on ties because tied readings share the same rank and can return 4 or more rows for a single sensor.
We solve this cleanly with two Common Table Expressions (CTEs)—named temporary query steps written with WITH ... AS (...)—and a window function, which is a calculation (OVER (...)) that attaches a group-relative number to each row without collapsing rows. Walk through sensor 10 from Example 1:
Input rows for sensor 10 (window is 2023-09-30 12:00:00 .. 2023-10-01 12:00:00):
(10, 88.0, '2023-09-29 18:00:00') -> dropped in Step 1 (too old)
(10, NULL, '2023-10-01 11:30:00') -> dropped in Step 1 (NULL value)
(10, 68.2, '2023-10-01 10:20:00') -> kept -> row_num = 4 -> dropped in Step 3
(10, 71.0, '2023-09-30 19:00:00') -> kept -> row_num = 3 -> returned!
(10, 71.0, '2023-10-01 09:45:00') -> kept -> row_num = 2 -> returned!
(10, 74.5, '2023-10-01 08:15:00') -> kept -> row_num = 1 -> returned!
Filtering first keeps 88.0 and NULL from stealing rank slots, ordering by (reading_value DESC, timestamp DESC) ranks the newer 71.0 ahead of the older 71.0 (and in Example 2's three-way tie at 55.0, keeps 09:30:00 and 08:15:00 over 07:00:00), and WHERE row_num <= 3 in the outer query caps each sensor at 3 rows.
Complexity
Let N be the total number of rows in sensor_readings and W be the number of valid rows inside the 24-hour window.
- Time: Without an index, the database scans all
Nrows to check theWHEREfilter, then sorts theWsurviving rows by(sensor_id, reading_value DESC, timestamp DESC)inO(W log W)time to assignROW_NUMBER(), and finally scans theWranked rows once to keeprow_num <= 3, forO(N + W log W)total time. With a B-tree index (a sorted tree structure that lets the database jump straight to a value range) ontimestamp, finding the 24-hour slice takesO(log N + W)instead ofO(N), reducing total work toO(log N + W log W). - Space:
O(W)temporary memory (or disk spill space) to hold and sort theWin-window rows while computingROW_NUMBER().
An index or partition key on timestamp helps far more than an index on (sensor_id, reading_value) because a 24-hour window is a tiny slice of years of telemetry history; indexing by value first still forces the engine to wade through old high readings.
Edge cases
- Exact boundary timestamps: Readings at
2023-09-30 12:00:00and2023-10-01 12:00:00are included (>=and<=), while2023-09-30 11:59:59and2023-10-01 12:00:01are excluded. - NULL
reading_valuerows: Filtered out inrecent_readingsbefore ranking so they never occupy a top-3 slot; a sensor with onlyNULLreadings returns 0 rows. - Fewer than 3 valid readings: Sensors with 1 or 2 valid rows get
row_num1 or 1..2, so all of their valid readings are returned. - Ties on
reading_value: Broken deterministically bytimestamp DESC, so four readings of85.0at08:00,09:00,10:00, and11:00return the09:00,10:00, and11:00rows. - Exact duplicate rows (same sensor, value, and timestamp):
ROW_NUMBER()still numbers them sequentially (1, 2, 3, ...), strictly capping output at 3 rows per sensor (if duplicates are network-retry artifacts rather than real measurements, useSELECT DISTINCTinrecent_readingsfirst). - Negative and zero values: Handled naturally by
DESCsorting (-1.5ranks higher than-5.0). - Empty table: Returns 0 rows with the exact column header
sensor_id, reading_value, timestamp.
Common mistakes
- Using
RANK()orDENSE_RANK()instead ofROW_NUMBER(): Tied values receive the same rank, allowing a sensor with ties in the top 3 to return 4, 5, or more rows. - Ranking all history before filtering the 24-hour window: Old peak values grab
row_num1..3 and then get removed by the timestamp filter, leaving active sensors with fewer than 3 rows. - Writing
WHERE row_num <= 3inside the sameSELECTasROW_NUMBER(): SQL evaluatesWHEREbefore window functions, causing a syntax/compilation error (misuse of aliased window function); computerow_numin a CTE first (or useQUALIFY row_num <= 3in dialects like DuckDB, Snowflake, and BigQuery that supportQUALIFY). - Forgetting
timestamp DESCin the windowORDER BY: Without a secondary sort key, SQL chooses arbitrarily among tiedreading_valuerows, producing non-deterministic results. - Relying on default
NULLsort order instead ofWHERE reading_value IS NOT NULL: SQLite sortsNULLlast inDESCorder, whereas PostgreSQL and Oracle sortNULLfirst inDESCorder unlessNULLS LASTor an explicitIS NOT NULLfilter is used. - Using
NOT INfor Part 1's anti-join: Ifbackup_sensorscontains even a singleNULL,x NOT IN (..., NULL)never evaluates toTRUE, silently returning an empty result set.
Follow-up questions
-
When two source tables are guaranteed to have no overlapping rows, how can you speed up combining them with UNION, and what caveat still applies? Switch from
UNIONtoUNION ALL. BecauseUNIONeliminates duplicates, the execution engine has to sort or hash the entire combined output—incurring heavy memory use and network shuffles—whereasUNION ALLstreams both inputs directly with zero comparison work. The key caveat is thatUNIONalso deduplicates rows within each individual table, soUNION ALLreturns the exact same result only when the two tables share no rows with each other and neither table has internal duplicate rows (if one side can contain internal duplicates, runSELECT DISTINCTon that side alone before combining withUNION ALL). -
How should you partition and sort
sensor_readingson disk once historical volume reaches multiple petabytes? Partition the table by a coarse time unit—typically by day (toDate(timestamp)) or by month (toYYYYMM(timestamp)), keeping each partition in the tens-to-hundreds-of-gigabytes sweet spot rather than creating millions of tiny per-sensor or hourly files. Time partitioning unlocks partition pruning (skipping whole data directories whose date bounds fall outside theWHEREclause), so a 24-hour query touches at most two daily partitions instead of petabytes of history, and aging out old data becomes an instant metadataDROP PARTITION. Inside each partition, cluster/sort rows by(sensor_id, timestamp)—for exampleENGINE = MergeTree PARTITION BY toDate(timestamp) ORDER BY (sensor_id, timestamp)in ClickHouse—so every sensor's time series sits contiguously on disk, compresses tightly, and groups efficiently. -
Why does a columnar database execute this per-sensor top-3 query differently from a row-oriented OLTP engine? A columnar database (such as ClickHouse, BigQuery, or Parquet-based lakehouses, where each column is stored in its own separate file segment rather than packing full rows side by side) reads only the
sensor_id,reading_value, andtimestampcolumns from storage, ignoring dozens of wide diagnostic or payload columns typical in production telemetry. Homogeneous column blocks also compress aggressively (delta encoding on timestamps, run-length encoding on sortedsensor_ids), run vectorized SIMD loops over arrays of values, and use per-block min/max zone maps (lightweight header summaries recording each block's minimum and maximum value) to skip out-of-window blocks without decompressing them. A row-oriented OLTP store with a B-tree index ontimestampshines for tiny point lookups, whereas a columnar engine dominates analytical scans across tens of millions of 24-hour readings—and in ClickHouse you can express the query compactly withORDER BY sensor_id, reading_value DESC, timestamp DESC LIMIT 3 BY sensor_id.
Follow-up questions
- When two source tables are guaranteed to have no overlapping rows, how can you speed up combining them with UNION, and what caveat still applies?
- How should you partition and sort `sensor_readings` on disk once historical volume reaches multiple petabytes?
- Why does a columnar database execute this per-sensor top-3 query differently from a row-oriented OLTP engine?
Similar questions
- Job Posting Engagement Metrics Excluding Non-Viewing Applicants
- Compute 7-Day DAU, D1 Retention, and Revenue Cohorts
- Class-Level 2024 Exam Summary with Zero-Filled Averages
- Summarizing Imaging Claims Spend and Fiscal Months
- Build Rolling User Features for Experiment Regression
- Week-over-Week Net Order Revenue Change