Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
340 B
12
Indexable
Never
WITH p AS 
    (SELECT DATE_TRUNC('month', created_at::date)::date AS month,
            DATE_TRUNC('year', created_at::date) AS year,
            SUM(costs) OVER (ORDER BY DATE_TRUNC('month', created_at::date)) AS total
    FROM tools_shop.costs
    )
SELECT month, 
       total
FROM p
WHERE year IN ('2017-01-01', '2018-01-01');