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
Exercise instructions
- Select
warehouse_name,usage_month, andcredits_used. - Add a
running_totalcolumn usingSUM(credits_used)partitioned bywarehouse_nameand ordered byusage_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;