DA0-002 Data Acquisition and Preparation Practice Question
A data analyst is working with a sales table that contains columns: sale_id, product_id, sale_date, and amount. They need to calculate a 7-day moving average of sales amount for each product, ordered by sale_date. Which window function syntax should they use?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
AVG(amount) OVER (PARTITION BY product_id ORDER BY sale_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
A moving average requires averaging over a frame of rows. Using AVG() with an ORDER BY in the OVER clause and a frame specification (ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) calculates the 7-day moving average.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
AVG(amount) OVER (PARTITION BY product_id ORDER BY sale_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
Why this is correct
Correct. This computes the average of the current and previous 6 rows per product.
- ✗
AVG(amount) OVER (PARTITION BY product_id ORDER BY sale_date)
Why it's wrong here
Without a frame, the default is range between unbounded preceding and current row, which is not a moving window.
- ✗
AVG(amount) OVER (ORDER BY sale_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
Why it's wrong here
Missing PARTITION BY product_id, so it would average across all products.
- ✗
SUM(amount) OVER (PARTITION BY product_id ORDER BY sale_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
Why it's wrong here
This calculates a moving sum, not an average.
Go deeper
Related to this question
About these practice questions
Courseiva writes every DA0-002 question from scratch — 986 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This DA0-002 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the DA0-002 exam.