Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
302 B
3
Indexable
Never
WITH current_year AS (
    SELECT 
        DATE_TRUNC('year', created_at)::DATE AS c_year,
        SUM(total_amt) AS sumtot
    FROM tools_shop.orders
    GROUP BY c_year
)
SELECT
    c_year,
    sumtot,
    sumtot - LEAD(sumtot, 1, sumtot)
 OVER (ORDER BY c_year) AS diff
FROM current_year