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, department, RANK() OVER PARTITION BY department ORDER BY salary DESC FROM employees;
AMissing parentheses around PARTITION BY and ORDER BY clauses.
BRANK() cannot be used with PARTITION BY.
CORDER BY cannot be used inside window functions.
Demployee_id must be included in PARTITION BY.
Step-by-Step Solution
Solution:
  1. Step 1: Check window function syntax

    Window functions require OVER() with parentheses enclosing PARTITION BY and ORDER BY.
  2. Step 2: Identify missing parentheses

    The query misses parentheses after OVER, causing syntax error.
  3. Final Answer:

    Missing parentheses around PARTITION BY and ORDER BY clauses. -> Option A
  4. Quick Check:

    OVER() must enclose PARTITION BY and ORDER BY [OK]
Quick Trick: Always use parentheses after OVER() for window clauses [OK]
Common Mistakes:
  • Omitting parentheses after OVER
  • Thinking ORDER BY is not allowed in window functions
  • Assuming all columns must be in PARTITION BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes