Окна строк
Окна срок задаются в физических единицах, строках.Например, если рамка окна задана выражением ROWS 5 PRECEDING
, то окно будет включать в себя до 6
строк: текущую и пять предыдущих (порядок определяется конструкцией ORDER BY
).
SELECT
id,
salary,
SUM(salary) OVER() AS s1,
SUM(salary) OVER(ORDER BY salary) AS s2,
SUM(salary) OVER(ORDER BY salary
ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS s3,
SUM(salary) OVER(ORDER BY salary
ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOWING) AS s4,
SUM(salary) OVER(ORDER BY salary
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS s5,
SUM(salary) OVER(ORDER BY salary
ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING) AS s6,
SUM(salary) OVER(ORDER BY salary
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS s7,
SUM(salary) OVER(ORDER BY salary ROWS 1 PRECEDING) AS s8
FROM
employee
ID SALARY S1 S2 S3 S4 S5 S6 S7 S8 ------------------------------------------------------------------------- 3 8.00 49.00 8.00 8.00 49.00 49.00 17.00 17.00 8.00 4 9.00 49.00 17.00 17.00 41.00 49.00 19.00 27.00 17.00 1 10.00 49.00 37.00 27.00 32.00 49.00 20.00 29.00 19.00 5 10.00 49.00 37.00 37.00 22.00 49.00 22.00 32.00 20.00 2 12.00 49.00 49.00 49.00 12.00 49.00 12.00 22.00 22.00