Bird
0
0

You want to assign ranks to employees based on their sales, but you want no gaps in ranking numbers even if some employees have the same sales. Which function should you use and why?

hard📝 Application Q15 of 15
PostgreSQL - Window Functions in PostgreSQL
You want to assign ranks to employees based on their sales, but you want no gaps in ranking numbers even if some employees have the same sales. Which function should you use and why?

Options:
A) ROW_NUMBER() because it gives unique numbers.
B) RANK() because it skips ranks after ties.
C) DENSE_RANK() because it assigns ranks without gaps after ties.
D) COUNT() because it counts rows.
ADENSE_RANK() because it assigns ranks without gaps after ties.
BRANK() because it skips ranks after ties.
CROW_NUMBER() because it gives unique numbers.
DCOUNT() because it counts rows.
Step-by-Step Solution
Solution:
  1. Step 1: Understand ranking requirements

    The requirement is to assign ranks with no gaps even if employees tie in sales.
  2. Step 2: Match functions to behavior

    ROW_NUMBER() gives unique numbers, ignoring ties. RANK() skips ranks after ties causing gaps. DENSE_RANK() assigns ranks without gaps after ties.
  3. Step 3: Choose correct function

    DENSE_RANK() fits the requirement perfectly.
  4. Final Answer:

    DENSE_RANK() because it assigns ranks without gaps after ties. -> Option A
  5. Quick Check:

    DENSE_RANK() = no gaps in ranks [OK]
Quick Trick: Use DENSE_RANK() to avoid gaps in ranking numbers [OK]
Common Mistakes:
  • Choosing RANK() and expecting no gaps
  • Using ROW_NUMBER() which ignores ties
  • Confusing COUNT() with ranking functions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes