Window functions in Snowflake
📖 Scenario: You work as a data analyst in a company that stores sales data in Snowflake. You want to analyze sales performance by calculating running totals and rankings within each region.
🎯 Goal: Build a Snowflake SQL query using window functions to calculate the running total of sales and rank salespeople by their sales amount within each region.
📋 What You'll Learn
Create a table called
sales with columns region, salesperson, and amount.Insert sample data into the
sales table with at least 5 rows.Write a query that uses the
SUM() OVER (PARTITION BY region ORDER BY amount) window function to calculate running totals.Write a query that uses the
RANK() OVER (PARTITION BY region ORDER BY amount DESC) window function to rank salespeople within each region.💡 Why This Matters
🌍 Real World
Window functions help analyze data trends and rankings within groups, useful in sales, finance, and reporting.
💼 Career
Understanding window functions is essential for data analysts and engineers working with cloud data warehouses like Snowflake.
Progress0 / 4 steps