CS FundamentalsHardGATE CS (PYQ pattern)
HR(id, mgr): (1,NULL), (2,1), (3,1), (4,2), (5,2), (6,4), (7,6), (8,3). The recursive query WITH RECURSIVE D(id, d) AS (SELECT id, 0 FROM HR WHERE mgr IS NULL UNION ALL SELECT HR.id, D.d + 1 FROM HR JOIN D ON HR.mgr = D.id) SELECT SUM(d) FROM D computes the depth of every employee below the root. What does it return?
- A. 15
- B. 19
- C. 12
- D. 4
Correct answer: A. 15
Depths: id1 = 0; ids 2, 3 = 1; ids 4, 5, 8 = 2; id 6 = 3; id 7 = 4. Sum = 0 + 2 + 6 + 3 + 4 = 15.
More DBMS and SQL questions
- UA(id, g, x): (1,1,10), (2,2,20), (3,3,30), (4,1,40). UB(g, bonus): (1,5), (2,7). After UPDATE UA SET x = x + (SELECT bonus FROM UB WHERE…
- IA(x): 1, 2, 3, NULL, 5 and IB(y): 2, 2, 5, 7. Let p = rows of IA satisfying x IN (SELECT y FROM IB), q = rows of IA satisfying x NOT IN…
- T1 executes W1(A), C1 and T2 executes R2(A), W2(B), C2, each in the stated order. Among all interleavings of the five operations, how many…
- Strict two-phase locking with shared locks for reads and exclusive for writes (a transaction already holding S can upgrade to X only if no…
- Transactions T1..T5 have timestamps equal to their numbers (T1 is oldest). Seven independent lock conflicts occur, written (requester…
- Log (LSN: record): 1: T1 update P1; 2: T2 update P2; 3: T1 update P3; 4: begincheckpoint, whose endcheckpoint records ATT = {T1, T2} and…