select_win_frame.sql 1.1 KB

123456789101112131415161718
  1. --!syntax_pg
  2. select
  3. x,
  4. sum(x) over (order by x rows between unbounded preceding and 1 preceding) as upp,
  5. sum(x) over (order by x rows between unbounded preceding and current row) as upc,
  6. sum(x) over (order by x rows between unbounded preceding and 1 following) as upf,
  7. sum(x) over (order by x rows between unbounded preceding and unbounded following) as upuf,
  8. sum(x) over (order by x rows between 2 preceding and 1 preceding) as pp,
  9. sum(x) over (order by x rows between 2 preceding and current row) as pc,
  10. sum(x) over (order by x rows between 2 preceding and 1 following) as pf,
  11. sum(x) over (order by x rows between 2 preceding and unbounded following) as puf,
  12. sum(x) over (order by x rows between current row and current row) as cc,
  13. sum(x) over (order by x rows between current row and 1 following) as cf,
  14. sum(x) over (order by x rows between current row and unbounded following) as cuf,
  15. sum(x) over (order by x rows between 1 following and 2 following) as ff,
  16. sum(x) over (order by x rows between 1 following and unbounded following) as fuf
  17. from (values (1),(2),(3),(4),(5),(6),(7)) a(x)