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?
⚠ Common exam trap
The trap is forgetting to partition by product_id or using the default frame, which results in a cumulative average instead of a moving average, or confusing SUM with AVG.
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)
The correct syntax uses AVG with OVER, partitioning by product_id to calculate per product, ordering by sale_date, and specifying ROWS BETWEEN 6 PRECEDING AND CURRENT ROW to include the current row and the previous six rows, yielding a 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
ROWS BETWEEN 6 PRECEDING AND CURRENT ROW defines a seven-row frame ending at the current row, giving a 7-day moving average. PARTITION BY product_id restarts the window per product, and ORDER BY sale_date ensures chronological ordering.
- ✗
AVG(amount) OVER (PARTITION BY product_id ORDER BY sale_date)
Why it's wrong here
Omitting a ROWS BETWEEN frame makes the window cumulative from the partition start, not a rolling seven-day average. It tempts because the PARTITION BY and ORDER BY clauses are correct, and it would be right if the requirement were a running total or running average rather than a moving window.
- ✗
AVG(amount) OVER (ORDER BY sale_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
Why it's wrong here
Omitting PARTITION BY product_id averages across every product sharing that date range, blending unrelated products into one figure. The frame clause is correct, which makes this tempting, but without partitioning, per-product moving averages cannot be produced; PARTITION BY is what separates each product's series.
- ✗
SUM(amount) OVER (PARTITION BY product_id ORDER BY sale_date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)
Why it's wrong here
SUM returns a 7-day rolling total, not the moving average the analyst needs, so the result is on the wrong scale entirely. It is tempting because the frame clause ROWS BETWEEN 6 PRECEDING AND CURRENT ROW is exactly right; that same windowing is what AVG requires, but the aggregate function must be AVG.
About these practice questions
Courseiva writes every DA0-002 question from scratch — 1,004 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 and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official CompTIA exam blueprint
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.