GROUP BY and HAVING
Learn how to summarize and interpret data.
Step 1: Start with a question
In the last lesson, you asked: What is the total salary cost for the whole company?
Now, let’s ask something smarter: “What’s the total salary cost for each department?” That’s where GROUP BY comes in; it summarizes data by group, not as a single total.
Prompt: Write a SQL query that shows each department and its total salary cost from the employees table.
Powered by AI
5 Prompts Remaining
Step 2: Run and observe
AI will likely produce:
Run it. This is your first grouped summary: each row is now one group, not one employee.
Reflect: