- WITH tmp AS
- (
- SELECT DISTINCT
- DATE_TRUNC('month', created_at) :: date AS dt,
- SUM(costs) OVER(PARTITION BY DATE_TRUNC('month', created_at) :: date) AS month_cost
- FROM tools_shop.costs
- ORDER BY DATE_TRUNC('month', created_at) :: date
- )
- SELECT dt,
- month_cost,
- month_cost - LAG(month_cost, 1, month_cost) OVER(ORDER BY dt) AS delta
- FROM tmp
Untitled
From Max, 4 Months ago, written in Plain Text, viewed 60 times.
This paste will perish in 1 Second.
URL http://codebin.org/view/9dd6b968
Embed
Download Paste or View Raw
— Expand Paste to full width of browser