QuestionQ176

VerifiedDeveloping Code for Data Processing using Python and SQL

A facilities-monitoring team is creating a near-real-time PowerBI dashboard from the Delta table device_readings:

Question Image

For every sensor, the team requires one row for each non-overlapping 5-minute interval, offset by 2 minutes (for example, intervals such as 00:02-00:07, 00:07-00:12, ...), containing the average temperature for that slice. The output must include each interval's start and end timestamps so downstream tools can correctly plot time-series bars.

Which query meets the requirement?

Explanation

A time-window grouping with a 5-minute duration and a 5-minute slide produces non-overlapping tumbling intervals. Supplying 2 minutes as the start offset aligns the intervals at 00:02, 00:07, 00:12, and so on. Grouping by device_id and the window, then selecting window.start, window.end, and AVG(temperature_c), returns one average-temperature row per sensor and interval. Databricks documents that window accepts time column, window duration, slide duration, and start offset, and exposes start and end timestamps on the window value.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!