Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
336 B
0
Indexable
Never
WITH
    gr_mon AS (SELECT CAST(DATE_TRUNC('month', created_at) AS date) AS month,
                      SUM(costs) AS month_cost      
               FROM tools_shop.costs
               GROUP BY month) 

SELECT *,
       month_cost - LAG(month_cost, 1, month_cost) OVER (ORDER BY month_cost) AS costs_from_previous
FROM gr_mon