Bird
0
0

Consider this query:

medium📝 query result Q5 of 15
PostgreSQL - Window Functions in PostgreSQL
Consider this query:
SELECT employee, salary, RANK() OVER w AS rank
FROM employees
WINDOW w AS (ORDER BY salary DESC)

What does the rank column represent?
ASalary multiplied by rank
BTotal number of employees
CRow number without ordering
DRank of employees ordered by salary descending
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the WINDOW clause

    The window w orders rows by salary descending.
  2. Step 2: Understand RANK() OVER w

    RANK() assigns ranks to rows ordered by salary descending, with ties sharing rank.
  3. Final Answer:

    Rank of employees ordered by salary descending -> Option D
  4. Quick Check:

    RANK() OVER window = ordered rank [OK]
Quick Trick: RANK() respects window ORDER BY clause [OK]
Common Mistakes:
  • Confusing RANK() with ROW_NUMBER()
  • Ignoring ORDER BY in window
  • Assuming rank is a multiplication

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes