$ ./guess_the_languageSQL & Databases
SQL & Databases · easy · #45

What is run on the row with id 2?

-- t(id, x): (1,1), (2,2), (3,3)
SELECT id,
  SUM(x) OVER (ORDER BY id) AS run
FROM t;
  1. 3
  2. 1
  3. 2
  4. 6
With ORDER BY the window is a running total: 1 + 2 = 3 at id 2.
Play SQL & Databases ▸