CS FundamentalsVery hardGATE CS · Amazon SQL round

EMP has salaries 300, 200, 200, 200, 150, 100 for six employees. Let QR select employees whose RANK() OVER (ORDER BY sal DESC) equals 3, and QD select employees whose DENSE_RANK() OVER (ORDER BY sal DESC) equals 3. The numbers of rows returned by QR and QD are respectively:

  1. A. 3 and 1
  2. B. 1 and 1
  3. C. 0 and 1
  4. D. 1 and 3

Correct answer: C. 0 and 1

RANK leaves gaps after ties: ranks are 1, 2, 2, 2, 5, 6, so no row has rank 3. DENSE_RANK gives 1, 2, 2, 2, 3, 4, so exactly one row (salary 150) has dense rank 3.

More DBMS and SQL questions

Exams that ask this topic