Bird
0
0

Identify the error in this query:

medium📝 Debug Q14 of 15
PostgreSQL - Window Functions in PostgreSQL
Identify the error in this query:
SELECT employee_id, salary, LEAD(salary) ORDER BY employee_id FROM employees;
AORDER BY should be inside LEAD() function
BMissing OVER() clause for LEAD function
CLEAD cannot be used with salary column
Demployee_id must be in GROUP BY clause
Step-by-Step Solution
Solution:
  1. Step 1: Check LEAD function syntax

    LEAD requires an OVER() clause to specify ordering and partitioning.
  2. Step 2: Analyze query structure

    The query uses LEAD(salary) without OVER(), causing a syntax error.
  3. Final Answer:

    Missing OVER() clause for LEAD function -> Option B
  4. Quick Check:

    Window functions need OVER() [OK]
Quick Trick: Always use OVER() with LEAD/LAG [OK]
Common Mistakes:
  • Omitting OVER() clause
  • Placing ORDER BY outside OVER()
  • Confusing window functions with aggregates

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes