CS FundamentalsHardGATE CS (PYQ pattern)
Table LV(id, v): (1,5), (2,9), (3,9), (4,3), (5,3). Let L be the sum over all rows of LAST_VALUE(v) OVER (ORDER BY v) and F the sum of FIRST_VALUE(v) OVER (ORDER BY v) (default frame). What are (L, F)?
- A. (15, 29)
- B. (45, 15)
- C. (29, 29)
- D. (29, 15)
Correct answer: D. (29, 15)
With the default frame (RANGE UNBOUNDED PRECEDING to CURRENT ROW, peers included) LAST_VALUE returns the last peer's value, i.e. v itself for every row: 5 + 9 + 9 + 3 + 3 = 29. FIRST_VALUE is the smallest v (3) for every row: 15.
More DBMS and SQL questions
- 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…
- 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…