Bird
0
0

Find the error in this query:

medium📝 Debug Q6 of 15
PostgreSQL - Window Functions in PostgreSQL
Find the error in this query:
SELECT employee, salary, RANK() OVER ORDER BY salary PARTITION BY department FROM employees;
AThe OVER() clause cannot be used without a GROUP BY clause.
BRANK() cannot be used with ORDER BY in window functions.
CThe PARTITION BY clause must come before ORDER BY inside the OVER() clause.
DThe query is missing a WHERE clause to filter departments.
Step-by-Step Solution
Solution:
  1. Step 1: Check OVER() clause syntax

    PARTITION BY must appear before ORDER BY inside the OVER() parentheses.
  2. Step 2: Identify error

    The query places ORDER BY before PARTITION BY, which is invalid syntax.
  3. Final Answer:

    The PARTITION BY clause must come before ORDER BY inside the OVER() clause. -> Option C
  4. Quick Check:

    PARTITION BY precedes ORDER BY in OVER() [OK]
Quick Trick: PARTITION BY must precede ORDER BY inside OVER() [OK]
Common Mistakes:
  • Swapping the order of PARTITION BY and ORDER BY inside OVER().
  • Assuming RANK() cannot be combined with ORDER BY.
  • Thinking OVER() requires GROUP BY.

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes