Use COUNT, SUM, AVG, MIN, MAX with GROUP BY and HAVING to aggregate and filter grouped data.
Aggregate Functions and GROUP BY
SELECT COUNT(*) FROM users;
SELECT COUNT(DISTINCT country) FROM users;
SELECT SUM(amount) FROM orders WHERE status = 'completed';
SELECT AVG(age) FROM users WHERE is_active = 1;
SELECT MIN(price), MAX(price) FROM products;
-- GROUP BY
SELECT country, COUNT(*) AS user_count
FROM users
GROUP BY country
ORDER BY user_count DESC;
-- GROUP BY with HAVING (filter after grouping)
SELECT user_id, COUNT(*) AS order_count
FROM orders
GROUP BY user_id
HAVING order_count >= 5;
-- GROUP_CONCAT
SELECT user_id, GROUP_CONCAT(tag ORDER BY tag SEPARATOR ', ') AS tags
FROM post_tags
GROUP BY user_id;