0
0
SQLquery~5 mins

RANK and DENSE_RANK difference in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the RANK() function do in SQL?
RANK() assigns a rank number to each row within a partition of a result set, with gaps in ranking when there are ties.
Click to reveal answer
beginner
How does DENSE_RANK() differ from RANK() in SQL?
DENSE_RANK() assigns ranks without gaps, so tied rows get the same rank and the next rank is the immediate next number.
Click to reveal answer
intermediate
If two rows tie for rank 2, what rank will the next row get with RANK()?
The next row will get rank 4, because RANK() leaves gaps after ties.
Click to reveal answer
intermediate
If two rows tie for rank 2, what rank will the next row get with DENSE_RANK()?
The next row will get rank 3, because DENSE_RANK() does not leave gaps after ties.
Click to reveal answer
intermediate
Why might you choose DENSE_RANK() over RANK()?
Choose DENSE_RANK() when you want continuous ranking numbers without gaps, useful for compact ranking lists.
Click to reveal answer
What happens to the rank numbers after a tie when using RANK()?
AThey skip numbers creating gaps
BThey assign the same rank to all rows
CThey reset to 1
DThey continue without gaps
Which function assigns ranks without gaps after ties?
ACOUNT()
BROW_NUMBER()
CRANK()
DDENSE_RANK()
If two rows tie for first place, what rank does the next row get with DENSE_RANK()?
A3
B2
C1
D4
Which ranking function can produce gaps in the ranking sequence?
ARANK()
BDENSE_RANK()
CROW_NUMBER()
DSUM()
What is a key difference between RANK() and DENSE_RANK()?
ARANK() assigns unique ranks, DENSE_RANK() does not
BDENSE_RANK() leaves gaps, RANK() does not
CRANK() leaves gaps after ties, DENSE_RANK() does not
DBoth assign ranks randomly
Explain how RANK() and DENSE_RANK() handle ties differently in SQL.
Think about what happens to the next rank number after a tie.
You got /3 concepts.
    Describe a scenario where you would prefer to use DENSE_RANK() instead of RANK().
    Consider when gaps in ranking numbers might confuse users.
    You got /3 concepts.