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)?

  1. A. (15, 29)
  2. B. (45, 15)
  3. C. (29, 29)
  4. 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

Exams that ask this topic