Bird
0
0

Using the same Sales table, what will be the output of SELECT Employee, DENSE_RANK() OVER (ORDER BY Amount DESC) AS DenseRank FROM Sales;?

medium📝 query result Q5 of 15
SQL - Window Functions Fundamentals
Using the same Sales table, what will be the output of SELECT Employee, DENSE_RANK() OVER (ORDER BY Amount DESC) AS DenseRank FROM Sales;?
A[{"Employee":"Alice","DenseRank":1},{"Employee":"Bob","DenseRank":2},{"Employee":"Charlie","DenseRank":2}]
B[{"Employee":"Alice","DenseRank":1},{"Employee":"Bob","DenseRank":2},{"Employee":"Charlie","DenseRank":3}]
C[{"Employee":"Alice","DenseRank":1},{"Employee":"Bob","DenseRank":1},{"Employee":"Charlie","DenseRank":3}]
D[{"Employee":"Alice","DenseRank":1},{"Employee":"Bob","DenseRank":1},{"Employee":"Charlie","DenseRank":2}]
Step-by-Step Solution
Solution:
  1. Step 1: Understand DENSE_RANK() behavior with ties

    Alice and Bob tie with Amount 100, both get DenseRank 1.
  2. Step 2: Assign DenseRank to Charlie

    Charlie has next distinct Amount (90), so gets DenseRank 2 without skipping ranks.
  3. Final Answer:

    [{"Employee":"Alice","DenseRank":1},{"Employee":"Bob","DenseRank":1},{"Employee":"Charlie","DenseRank":2}] -> Option D
  4. Quick Check:

    DENSE_RANK no gaps after ties = D [OK]
Quick Trick: DENSE_RANK assigns consecutive ranks even with ties [OK]
Common Mistakes:
  • Skipping ranks like RANK() does
  • Assigning wrong rank numbers to tied rows
  • Confusing output with RANK()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes