Bird
0
0

What is wrong with the following query?

medium📝 Debug Q6 of 15
PostgreSQL - Window Functions in PostgreSQL
What is wrong with the following query?
SELECT employee_id, RANK() score OVER (ORDER BY score DESC) FROM employees;
AThe alias 'score' is placed incorrectly between RANK() and OVER()
BRANK() cannot be used with ORDER BY clause
CMissing PARTITION BY clause inside OVER()
DRANK() requires a parameter inside the parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the syntax of RANK()

    The correct syntax is RANK() OVER (ORDER BY column). The alias should come after the entire expression.
  2. Step 2: Identify the error

    In the query, 'score' is incorrectly placed between RANK() and OVER(), which is invalid.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Alias must be after the window function expression [OK]
Quick Trick: Alias goes after window function, not inside parentheses [OK]
Common Mistakes:
  • Placing alias inside function parentheses
  • Misordering alias and OVER() clause
  • Assuming RANK() needs parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes