Bird
0
0

What is wrong with this query?

medium📝 Debug Q7 of 15
PostgreSQL - Window Functions in PostgreSQL
What is wrong with this query?
SELECT player, score, AVG(score) OVER (ORDER BY score RANGE BETWEEN 2 PRECEDING AND CURRENT ROW) FROM players;
AAVG cannot be used with RANGE frame.
BRANGE frame cannot use numeric offsets like '2 PRECEDING'.
CORDER BY clause is missing.
DThe query is correct and will run without errors.
Step-by-Step Solution
Solution:
  1. Step 1: Understand RANGE frame limits

    RANGE requires value expressions, not row counts like '2 PRECEDING'.
  2. Step 2: Identify error

    Using '2 PRECEDING' with RANGE causes syntax error.
  3. Final Answer:

    RANGE frame cannot use numeric offsets like '2 PRECEDING'. -> Option B
  4. Quick Check:

    RANGE needs value offsets, not row counts [OK]
Quick Trick: Use INTERVAL or value expressions with RANGE, not row counts [OK]
Common Mistakes:
  • Using PRECEDING/FOLLOWING with RANGE incorrectly
  • Assuming RANGE works like ROWS
  • Ignoring syntax rules for window frames

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes