Bird
0
0

Which window frame clause would you use to calculate a moving average over the current row and the two previous rows?

easy📝 Conceptual Q2 of 15
SQL - Advanced Window Functions
Which window frame clause would you use to calculate a moving average over the current row and the two previous rows?
AROWS BETWEEN CURRENT ROW AND 2 FOLLOWING
BROWS BETWEEN 2 PRECEDING AND CURRENT ROW
CROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
DROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct frame for two previous rows plus current

    The frame should start 2 rows before and end at the current row.
  2. Step 2: Match with the options

    ROWS BETWEEN 2 PRECEDING AND CURRENT ROW matches this: ROWS BETWEEN 2 PRECEDING AND CURRENT ROW.
  3. Final Answer:

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

    Two previous + current row = 2 PRECEDING to CURRENT [OK]
Quick Trick: Preceding means rows before current, following means after [OK]
Common Mistakes:
  • Confusing preceding with following
  • Using unbounded which includes all previous rows
  • Selecting a frame that excludes current row

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes