CS FundamentalsVery hardGATE CS

S(v) holds the nine rows 10, 20, 20, 30, 30, 30, 40, 40, 50. The query SELECT SUM(v) OVER (ORDER BY v) FROM S uses the default frame. What is the total of the nine values it returns?

  1. A. 1090
  2. B. 570
  3. C. 1270
  4. D. 1240

Correct answer: D. 1240

With ORDER BY and no frame clause the frame is RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW, so rows with equal v are peers and receive the same running sum: the nine outputs add to 1240. An explicit ROWS frame would give 1090.

More DBMS and SQL questions

Exams that ask this topic