Running Totals & Moving Averages — Concept Check
Questions on Running Totals & Moving Averages. Frame clauses (ROWS BETWEEN / RANGE BETWEEN) control which rows contribute to each window computation, enabling running sums, moving averages, and partition-resetting accumulators.
Questions in this quiz
8 questions on Running Totals & Moving Averages — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A database query calculates a running total of sales per month using ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW. What happens if the ORDER BY clause is removed?
- AThe running total will calculate correctly but slower.
- BThe running total will not function correctly.
- CThe query will fail to execute.
- DThe running total will reset for each row.
2.A report calculates a 7-day moving average of daily sales using ROWS BETWEEN 6 PRECEDING AND CURRENT ROW. What is the impact of using RANGE instead of ROWS?
- AThe moving average will always include exactly 7 days.
- BThe moving average may include more than 7 days due to ties.
- CThe moving average will be faster to compute.
- DThe moving average will exclude the current day.
3.A developer uses PARTITION BY user_id and ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW for a running total. What is the effect?
- AThe running total accumulates across all users.
- BThe running total includes only the first transaction.
- CThe running total resets for each day.
- DThe running total resets for each user.
4.For a 7-day moving average of daily orders, why might ROWS be preferred over RANGE?
- AROWS automatically adjusts for weekends.
- BROWS includes future dates for prediction.
- CROWS is faster than RANGE for moving averages.
- DROWS avoids including extra days with the same date.
5.A query uses SUM(amount) OVER (ORDER BY created_at ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW). What is this calculating?
- AA cumulative sum that resets each month.
- BA moving average over the last 7 rows.
- CA total sum of all rows in the table.
- DA running total from the start to the current row.
6.A developer believes using RANGE BETWEEN will always include the same number of rows as ROWS BETWEEN. What is the truth?
- ARANGE always includes fewer rows than ROWS.
- BRANGE may include more rows due to tied values.
- CRANGE is only used for moving averages.
- DRANGE and ROWS always include the same rows.
7.What happens if ROWS BETWEEN 6 PRECEDING AND CURRENT ROW is used without an ORDER BY clause?
- AThe query will not execute correctly.
- BThe moving average will include future dates.
- CThe query will execute faster.
- DThe moving average will be calculated correctly.
8.A developer uses RANGE BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING for a running total. What might go wrong?
- AThe running total will reset for each partition.
- BThe running total will be calculated correctly.
- CThe running total will only include the first row.
- DThe running total may include future rows unexpectedly.