In SQL window functions, which frame specification yields a 7-day running total when ordering by date?

Prepare for the DDR Data Science Interview. Practice with detailed questions and explanations to enhance your knowledge. Ace your interview!

Multiple Choice

In SQL window functions, which frame specification yields a 7-day running total when ordering by date?

Explanation:
Understanding how window frame definitions control the set of rows included for each calculation is key. To get a 7-day running total when sorting by date, you want a frame that includes the current row and the six preceding rows. The specification ROWS BETWEEN 6 PRECEDING AND CURRENT ROW does exactly that, giving seven rows in the window for each date (assuming one row per day). The other frames don’t meet this goal: including a following row pulls in future data, a frame that starts only one day before covers too few rows, and unbounded frames would sum all rows in the partition. Remember this is row-based, so if there are missing dates, you won’t always have seven calendar days—just seven available rows.

Understanding how window frame definitions control the set of rows included for each calculation is key. To get a 7-day running total when sorting by date, you want a frame that includes the current row and the six preceding rows. The specification ROWS BETWEEN 6 PRECEDING AND CURRENT ROW does exactly that, giving seven rows in the window for each date (assuming one row per day). The other frames don’t meet this goal: including a following row pulls in future data, a frame that starts only one day before covers too few rows, and unbounded frames would sum all rows in the partition. Remember this is row-based, so if there are missing dates, you won’t always have seven calendar days—just seven available rows.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy