PostgreSQLWindow FunctionsLAG
NTILE

LAGWindow Functions

LEAD

Returns the value from n rows before the current row.

Syntax

LAG(expr [, n [, default]]) OVER (w)

Example

Enter values below to update the example in real time.

order_month
revenue
prev_month_revenue
monthly_sales
SELECT order_month, revenue,
       LAG(revenue) OVER (ORDER BY order_month) AS prev_month_revenue
FROM monthly_sales;