Bird
0
0

You want to compute a moving average of the current and previous two sales amounts ordered by sale_date. Which window frame clause correctly achieves this?

hard📝 Application Q8 of 15
SQL - Window Functions Fundamentals
You want to compute a moving average of the current and previous two sales amounts ordered by sale_date. Which window frame clause correctly achieves this?
AROWS BETWEEN 2 PRECEDING AND CURRENT ROW
BROWS BETWEEN CURRENT ROW AND 2 FOLLOWING
CROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
DROWS BETWEEN 3 PRECEDING AND 1 PRECEDING
Step-by-Step Solution
Solution:
  1. Step 1: Define the frame for moving average

    To include the current row and the two previous rows, the frame should start 2 rows before and end at the current row.
  2. Step 2: Match with options

    ROWS BETWEEN 2 PRECEDING AND CURRENT ROW specifies ROWS BETWEEN 2 PRECEDING AND CURRENT ROW, which matches the requirement.
  3. Final Answer:

    ROWS BETWEEN 2 PRECEDING AND CURRENT ROW -> Option A
  4. Quick Check:

    Moving average includes current and 2 previous rows [OK]
Quick Trick: Use 2 PRECEDING to CURRENT ROW for last 3 rows [OK]
Common Mistakes:
  • Using FOLLOWING instead of PRECEDING
  • Including more rows than needed
  • Using UNBOUNDED PRECEDING which includes all prior rows

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes