Untitled

Anonymous
plain_text
06/16/2023 9:50 AM
404 B
18
Indexable
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
Editor is loading...