CS FundamentalsVery hardGATE CS (PYQ pattern)
Table P(n, s): (a,90), (b,85), (c,85), (d,70), (e,70), (f,70), (g,60). A query computes r = RANK() OVER (ORDER BY s DESC) and d = DENSE_RANK() OVER (ORDER BY s DESC) for each row. For how many rows is r - d exactly 2?
- A. 3
- B. 0
- C. 1
- D. 2
Correct answer: B. 0
Ranks: a r1 d1; b,c r2 d2 (gap 0); d,e,f r4 d3 (gap 1); g r7 d4 (gap 3). Gaps are 0, 0, 1, 3, so r - d = 2 never occurs.
More DBMS and SQL questions
- Table W(id, dept, sal): (1,A,50), (2,A,70), (3,A,90), (4,B,40), (5,B,40), (6,C,100), (7,C,20), (8,C,NULL), (9,D,NULL). SELECT COUNT() FROM…
- A1(x) holds 1, 1, 1, 2, 2, 3, NULL, NULL and B1(x) holds 1, 2, 2, 2, NULL, 4. Using the standard bag semantics (a value occurring m times…
- Tables ST(s, c) with rows (p,DB), (p,OS), (p,CN), (q,DB), (q,OS), (r,DB), (r,OS), (r,CN), (r,AI), (s,CN), (s,OS), (s,DB), (s,DB) and…
- Edge table G(a, b): (1,2), (2,3), (3,1), (3,4), (4,5), (6,7). The recursive query WITH RECURSIVE R(x,y) AS (SELECT a,b FROM G UNION SELECT…
- Table M(g, v): (x,10), (x,NULL), (x,20), (y,NULL), (y,NULL), (z,30). How many groups does SELECT g FROM M GROUP BY g HAVING COUNT() >…
- O(oid, c): (1,100), (2,100), (3,200), (4,NULL). I(oid, p, q): (1,5,2), (1,6,1), (2,5,3), (3,7,1), (3,7,1), (9,1,1). C(c, n): (100,u)…