Associate Data Practitioner Exam QuestionsBrowse all questions from this exam

Associate Data Practitioner Exam - 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?

Show Answer
Correct Answer:

Discussion

3 comments
Sign in to comment
trashboxOption: C
Jan 22, 2025

Should be partitioned by store_id to keep averages separate: A or C Then, should be ordered by date for chronological window calculation: C

n2183712847Option: C
Mar 6, 2025

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.

NishantRanjanKhawareOption: C
May 3, 2025

Should be partitioned by store id to get the store based sales, also, to check the weekly average sales, the ROWS between 6 preceeding and current row function will cater to it.