PostgreSQL(WIP)
Window Function
OVER()
Window Frames
unbounded
preceding
following
current row
Sample raw data
default behavior is
unbounded preceding
select name, sum(price) over(order by name)
from orderssame as
select name, sum(price) over(order by name range between unbounded preceding and current row)
from ordersInclude current row and previous N rows
range can only be used with unbounded
select name, sum(price) over(order by name rows between 2 preceding and current row)
from ordersselect name, sum(price) over(order by name range between current row and unbounded following)
from ordersselect name, sum(price) over(order by name rows between current row and 2 following)
from ordersselect name, sum(price) over(order by name rows between 2 preceding and 2 following)
from ordersselect name, sum(price) over(order by name range between unbounded preceding and unbounded following)
from orderssame as
select name, sum(price) over()
from orders
order by nameLast updated
Was this helpful?