Get startedGet started for free

Running totals with SUM

Harbr's finance team wants to track how credit consumption accumulates over time for each warehouse. You'll build a running total using SUM() as a window function on logistics.warehouse_usage, which contains warehouse_name, usage_month, and credits_used.

This exercise is part of the course

Data Pipeline Automation in Snowflake

View Course

Exercise instructions

  • Select warehouse_name, usage_month, and credits_used.
  • Add a running_total column using SUM(credits_used) partitioned by warehouse_name and ordered by usage_month.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

SELECT
    warehouse_name,
    usage_month,
    credits_used,
    -- Running total of credits per warehouse
    ___(___) OVER(
        PARTITION BY ___
        ORDER BY usage_month
    ) AS running_total
FROM logistics.warehouse_usage
ORDER BY warehouse_name, usage_month;
Edit and Run Code