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)?
- A. (5, 6, 7)
- B. (5, 5, 7)
- C. (5, 6, 6)
- 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
- SP(id, s): (1,10), (2,10), (3,10), (4,20), (5,20), (6,30), (7,NULL), (8,NULL). How many rows does SELECT FROM SP a JOIN SP b ON a.s = b.s…
- Table T(x) has 4 rows. How many rows does each of these return? (a) SELECT COUNT() FROM T HAVING COUNT() > 5; (b) SELECT COUNT() FROM T…
- Which of the following statements about standard SQL are correct? I. A column alias defined in the SELECT list can be used in ORDER BY…
- X1(a): 1, 1, 2, 2, 3, 4 and Y1(a): 2, 4, 5. Let p = rows from SELECT a FROM X1 WHERE a NOT IN (SELECT a FROM Y1) and q = rows from SELECT…
- Tables: P(id); C(id, p) with p referencing P(id) ON DELETE CASCADE; G(id, c) with c referencing C(id) ON DELETE SET NULL. Rows: P = {1…
- Optimistic concurrency control with backward validation. Transactions (start, validation, finish times; read set; write set): T1 (0, 4, 5…