Topic 1 Question 2
Your company has several retail locations. Your company tracks the total number of sales made at each location each day. You want to use SQL to calculate the weekly moving average of sales by location to identify trends for each store. Which query should you use?
-------------------------
-------------------------
-------------------------
-------------------------
ユーザの投票
コメント(2)
- 正解だと思う選択肢: C
Should be partitioned by store_id to keep averages separate: A or C Then, should be ordered by date for chronological window calculation: C
👍 1trashbox2025/01/22 - 正解だと思う選択肢: C
The best option is C. Option C is best because it correctly partitions by store_id to calculate the moving average for each store individually, and orders by date to ensure the moving average is calculated chronologically over the preceding 7 days (including the current day, thus 6 preceding). ROWS BETWEEN 6 PRECEDING AND CURRENT ROW then correctly defines the 7-day window for the average. Option A is incorrect because it orders by total_sales instead of date, making the rolling average based on sales value order, not time, which is illogical for a weekly trend. Option B is incorrect because it partitions by date instead of store_id, calculating a daily moving average across all stores, not per store. Option D is incorrect because it partitions by total_sales, which is nonsensical for analyzing trends by location, and orders by date within that illogical partition. Therefore, Option C is the only query that correctly calculates a weekly moving average of sales by store location.
👍 1n21837128472025/03/05
シャッフルモード