Bird
0
0

What is the purpose of using a window frame clause like ROWS BETWEEN 1 PRECEDING AND CURRENT ROW in a moving average calculation?

easy📝 Conceptual Q1 of 15
SQL - Advanced Window Functions
What is the purpose of using a window frame clause like ROWS BETWEEN 1 PRECEDING AND CURRENT ROW in a moving average calculation?
ATo calculate the average including the current row and the one before it
BTo calculate the average of all rows in the table
CTo calculate the average excluding the current row
DTo calculate the average of only the first row
Step-by-Step Solution
Solution:
  1. Step 1: Understand the window frame clause

    The clause ROWS BETWEEN 1 PRECEDING AND CURRENT ROW means the window includes the current row and the one immediately before it.
  2. Step 2: Apply to moving average calculation

    Calculating average over this window means averaging the current row's value and the previous row's value.
  3. Final Answer:

    To calculate the average including the current row and the one before it -> Option A
  4. Quick Check:

    Window frame clause = Current + 1 preceding row [OK]
Quick Trick: Window frames define which rows to include in calculations [OK]
Common Mistakes:
  • Thinking it averages all rows in the table
  • Ignoring the 'preceding' keyword
  • Assuming it excludes the current row

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes