PostgreSQLウィンドウ関数LEAD
LAG

LEADウィンドウ関数

FIRST_VALUE

現在行からn行後の値を返します。

構文

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

使用例

下記の値を入力するとサンプルに即時反映されます。

order_month
revenue
next_month_revenue
monthly_sales
SELECT order_month, revenue,
       LEAD(revenue) OVER (ORDER BY order_month) AS next_month_revenue
FROM monthly_sales;