Bird
0
0

Identify the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Window Functions in PostgreSQL
Identify the error in this query:
SELECT customer_id, FIRST_VALUE(amount) OVER (PARTITION BY customer_id ORDER BY order_date ROWS UNBOUNDED PRECEDING) FROM orders;
ASyntax error due to missing parentheses
BMissing frame end in ROWS clause
CFIRST_VALUE cannot be used with PARTITION BY
DORDER BY cannot be used inside OVER clause
Step-by-Step Solution
Solution:
  1. Step 1: Check frame clause syntax

    The frame clause ROWS UNBOUNDED PRECEDING is incomplete; it requires an end boundary like AND CURRENT ROW.
  2. Step 2: Validate other parts

    ORDER BY is valid in OVER, PARTITION BY is allowed, and parentheses are correct.
  3. Final Answer:

    Missing frame end in ROWS clause -> Option B
  4. Quick Check:

    Frame clause must have start and end [OK]
Quick Trick: ROWS frame needs start and end boundaries [OK]
Common Mistakes:
  • Omitting frame end boundary
  • Misplacing ORDER BY clause
  • Confusing window function syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes