CS FundamentalsVery hardGATE CS (PYQ pattern)

Table S(id, v): (1,10), (2,20), (3,20), (4,30), (5,30), (6,40). SELECT SUM(v) OVER (ORDER BY v) AS s FROM S ORDER BY id; What is the sum of the six values s that the query returns?

  1. A. 480
  2. B. 430
  3. C. 210
  4. D. 520

Correct answer: A. 480

With ORDER BY and no frame clause the default frame is RANGE UNBOUNDED PRECEDING, so rows with equal v are peers and share the same running total: [10, 50, 50, 110, 110, 150]. With ROWS the totals would be [10, 30, 50, 80, 110, 150].

More DBMS and SQL questions

Exams that ask this topic