Bird
0
0

Why does the ROW_NUMBER() window function produce different results than RANK() when there are ties in the ordering column?

hard📝 Conceptual Q10 of 15
PostgreSQL - Window Functions in PostgreSQL
Why does the ROW_NUMBER() window function produce different results than RANK() when there are ties in the ordering column?
AROW_NUMBER() counts rows per partition; RANK() counts total rows
BROW_NUMBER() assigns unique sequential numbers ignoring ties; RANK() assigns same rank to ties and skips ranks after
CROW_NUMBER() cannot be used with ORDER BY; RANK() requires ORDER BY
DROW_NUMBER() groups tied rows together; RANK() always assigns unique numbers
Step-by-Step Solution
Solution:
  1. Step 1: Understand ROW_NUMBER() behavior with ties

    ROW_NUMBER() assigns a unique sequential number to each row, ignoring ties, so tied rows get different numbers.
  2. Step 2: Understand RANK() behavior with ties

    RANK() assigns the same rank to tied rows and skips subsequent ranks accordingly, causing gaps.
  3. Final Answer:

    ROW_NUMBER() assigns unique sequential numbers ignoring ties; RANK() assigns same rank to ties and skips ranks after -> Option B
  4. Quick Check:

    ROW_NUMBER() unique; RANK() ties share rank with gaps [OK]
Quick Trick: ROW_NUMBER() unique; RANK() ties share rank with gaps [OK]
Common Mistakes:
  • Thinking ROW_NUMBER() groups ties
  • Assuming RANK() always assigns unique numbers
  • Confusing function purposes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes