Bird
0
0

What is wrong with this query?

medium📝 Debug Q6 of 15
PostgreSQL - Window Functions in PostgreSQL
What is wrong with this query?
SELECT employee_id, salary, SUM(salary) OVER PARTITION BY department ORDER BY employee_id FROM employees;
AIncorrect use of ORDER BY outside OVER clause
BMissing parentheses around the OVER clause
CSUM() cannot be used with window functions
Demployee_id cannot be selected with window functions
Step-by-Step Solution
Solution:
  1. Step 1: Check OVER clause syntax

    The OVER clause must be enclosed in parentheses.
  2. Step 2: Identify missing parentheses

    Query uses OVER PARTITION BY without parentheses, which is invalid.
  3. Final Answer:

    Missing parentheses around the OVER clause -> Option B
  4. Quick Check:

    OVER clause requires parentheses [OK]
Quick Trick: Always use parentheses after OVER [OK]
Common Mistakes:
  • Omitting parentheses in OVER clause
  • Placing ORDER BY outside OVER clause
  • Believing SUM() can't be window function

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes