Using CASE with Aggregate Functions in SQL
📖 Scenario: You work for a retail company that wants to analyze sales data. The company wants to see how many sales were made in different regions and categorize them as 'High' or 'Low' sales based on the total sales amount.
🎯 Goal: Build an SQL query that uses the CASE statement combined with aggregate functions to categorize total sales by region as 'High' or 'Low'.
📋 What You'll Learn
Create a table called
sales with columns region (text) and amount (integer).Insert the exact sales data provided into the
sales table.Write a query that sums sales amounts grouped by
region.Use a
CASE statement with the aggregate SUM(amount) to label sales as 'High' if total is 1000 or more, otherwise 'Low'.💡 Why This Matters
🌍 Real World
Retail companies often analyze sales data by region to make business decisions. Using CASE with aggregate functions helps categorize and summarize data efficiently.
💼 Career
SQL skills like using CASE with aggregates are essential for data analysts and database developers to create meaningful reports and insights.
Progress0 / 4 steps