$ ./guess_the_languageSQL & Databases
SQL & Databases · hard · #47

What is s on the row (1,1)?

-- t(d, x): (1,1), (1,2), (2,3)
SELECT d, x,
  SUM(x) OVER (ORDER BY d) AS s
FROM t;
  1. 1
  2. 6
  3. 2
  4. 3
The default frame is RANGE ... CURRENT ROW, which includes peers with the same d, so both d=1 rows sum to 3.
Play SQL & Databases ▸