Bird
0
0

What does the SQL clause ROWS BETWEEN 2 PRECEDING AND CURRENT ROW do in a window function?

easy📝 Conceptual Q11 of 15
SQL - Advanced Window Functions
What does the SQL clause ROWS BETWEEN 2 PRECEDING AND CURRENT ROW do in a window function?
AIt calculates the function over the current row and the two rows before it.
BIt calculates the function over the current row and the next two rows.
CIt calculates the function over all rows in the table.
DIt calculates the function only on the current row.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the window frame boundaries

    The clause ROWS BETWEEN 2 PRECEDING AND CURRENT ROW means the frame includes the current row and the two rows before it.
  2. Step 2: Apply to window function calculation

    The window function (like AVG) will compute its result using values from these three rows.
  3. Final Answer:

    It calculates the function over the current row and the two rows before it. -> Option A
  4. Quick Check:

    Window frame includes current + 2 preceding rows = C [OK]
Quick Trick: Preceding means rows before current, including current [OK]
Common Mistakes:
  • Confusing PRECEDING with FOLLOWING
  • Thinking it includes future rows
  • Assuming it covers entire table

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes