1. Home
  2. Data Science
  3. SQL for Data Analysis
  4. Values 100, 100, 90 are ranked in descending order. What…

Added 30 Nov -0001

Values 100, 100, 90 are ranked in descending order. What do RANK, DENSE_RANK and ROW_NUMBER produce?

  1. 1,2,3 for all three functions, because every row receives a distinct sequential position
  2. 1,1,2 for RANK and 1,1,3 for DENSE_RANK, with 1,2,3 for ROW_NUMBER in the very same single query
  3. 1,1,3 for RANK; 1,1,2 for DENSE_RANK; and 1,2,3 for ROW_NUMBER with an arbitrary tie order Correct answer
  4. 1,1,3 for all three, since ties always skip a position whatever function is used

Correct answer

C. 1,1,3 for RANK; 1,1,2 for DENSE_RANK; and 1,2,3 for ROW_NUMBER with an arbitrary tie order

15 views

MCQSEXAM

Explanation

Ranking functions differ only in tie handling: RANK leaves a gap after a tie, DENSE_RANK does not, and ROW_NUMBER assigns consecutive integers arbitrarily among tied rows. Using ROW_NUMBER for deduplication is therefore non-deterministic unless the ORDER BY is a total order. Adding a unique tiebreaker column is the standard fix.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More SQL for Data Analysis MCQs

Practise all SQL for Data Analysis MCQs

Similar MCQs