Part 53: Grouping Data with the GROUP BY Clause
GROUP BY groups rows that share identical values in specified columns, allowing aggregate calculations per group.
1. Basic Syntax
SELECT
department,
COUNT(*) AS employee_count,
ROUND(AVG(salary), 2) AS average_salary
FROM employees
GROUP BY department;
The Golden Rule of GROUP BY: Any column in the
SELECTlist that is not inside an aggregate function must appear in theGROUP BYclause!
Key Takeaways
GROUP BYorganizes rows into summary buckets.- All non-aggregated select columns must be declared in
GROUP BY.
In Part 54, we explore Filtering Aggregations with the HAVING Clause (HAVING vs WHERE)!

