CS FundamentalsVery hardGATE CS (PYQ pattern)

TP(g, id, s): (a,1,90), (a,2,90), (a,3,80), (a,4,70), (b,5,60), (b,6,60), (b,7,60), (c,8,50). Let n1, n2, n3 be the numbers of rows with rank <= 2 when the rank is ROW_NUMBER(), RANK(), DENSE_RANK() respectively, each computed OVER (PARTITION BY g ORDER BY s DESC). What is (n1, n2, n3)?

  1. A. (5, 6, 7)
  2. B. (5, 5, 7)
  3. C. (5, 6, 6)
  4. D. (6, 5, 7)

Correct answer: A. (5, 6, 7)

ROW_NUMBER caps every partition at 2 rows (2 + 2 + 1 = 5). RANK: group a has ranks 1, 1, 3, 4 so 2 rows qualify; b has 1, 1, 1 (3 rows); c has 1 (1 row): 6 rows. DENSE_RANK: a has 1, 1, 2, 3 (3 rows), b 3 rows, c 1 row: 7.

More DBMS and SQL questions

Exams that ask this topic