Databricks Certified Data Analyst Associate · Free Practice Question Medium
Question 10
Assuming you have a table TrafficData with columns Timestamp (timestamp) and VehicleCount (integer), and you need to calculate the sum of VehicleCount for every 10-minute window.
Which SQL query using the window_time function correctly achieves this in a Databricks environment?
-
A
SELECT Timestamp, SUM(VehicleCount) OVER (ORDER BY Timestamp RANGE BETWEEN INTERVAL 10 MINUTES PRECEDING AND CURRENT ROW) FROM TrafficData; -
B
SELECT window_time(Timestamp, '10 minutes'), COUNT(VehicleCount) FROM TrafficData GROUP BY Timestamp; -
C
SELECT window_time(Timestamp, '10 minutes'), AVG(VehicleCount) FROM TrafficData GROUP BY window_time(Timestamp, '10 minutes'); -
D
SELECT window_time(Timestamp, '10 minutes'), SUM(VehicleCount) FROM TrafficData GROUP BY window_time(Timestamp, '10 minutes'); -
E
SELECT Timestamp, SUM(VehicleCount) OVER (PARTITION BY window_time(Timestamp, '10 minutes')) FROM TrafficData;
Reveal correct answer
Correct answer: D
Explanation
This question tests the understanding of using the window_time function for time-based aggregation in SQL, a common requirement for analyzing time-series data such as traffic counts.
References:
https://learn.microsoft.com/en-us/azure/databricks/sql/language-manual/functions/window_time
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
