Services Work Learn About Contact
0/9
Lesson 8 of 9

GROUP BY & Aggregates

GROUP BY groups rows that have the same values. Use aggregate functions like COUNT(), SUM(), AVG(), MAX(), and MIN() to calculate values for each group.

SQL
-- Count users per country
SELECT country, COUNT(*) as total_users
FROM users
GROUP BY country;

-- Average price per category
SELECT category, AVG(price) as avg_price
FROM products
GROUP BY category;

-- Having filters groups (like WHERE for groups)
SELECT country, COUNT(*) as total
FROM users
GROUP BY country
HAVING total > 10;
🧠

Quick Quiz

Answer correctly to unlock the next lesson.

Support the mission

This learning platform is 100% free: no ads, no tracking, no paywalls. If it helped you learn something useful, you can support future lessons or donate to Doctors Without Borders, which provides emergency medical care in crisis zones worldwide.

🎉

You completed SQL!

You finished all 9 lessons and quizzes. You now know the basics of SQL.