Bird
0
0

Consider the table Orders with columns Customer and Total:

medium📝 query result Q4 of 15
SQL - Window Functions Fundamentals
Consider the table Orders with columns Customer and Total:
Customer | Total
Anna | 200
Ben | 200
Clara | 150

What will be the result of this query?
SELECT Customer, RANK() OVER (ORDER BY Total DESC) AS Rank FROM Orders;
AAnna - 1, Ben - 1, Clara - 3
BAnna - 1, Ben - 2, Clara - 3
CAnna - 1, Ben - 1, Clara - 2
DAnna - 2, Ben - 2, Clara - 3
Step-by-Step Solution
Solution:
  1. Step 1: Understand RANK() behavior

    RANK() assigns the same rank to ties but skips subsequent ranks accordingly.
  2. Step 2: Apply to data

    Anna and Ben both have 200, so both get rank 1. Clara has 150, so rank is 3 (rank 2 is skipped).
  3. Final Answer:

    Anna - 1, Ben - 1, Clara - 3 -> Option A
  4. Quick Check:

    Check for skipped rank after ties [OK]
Quick Trick: RANK() skips ranks after ties [OK]
Common Mistakes:
  • Assuming ranks are consecutive after ties
  • Confusing RANK() with DENSE_RANK()
  • Assigning different ranks to tied values

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes