Geek Slack

My SQL Tutorial
About Lesson


GROUP BY Statement


GROUP BY Statement

The GROUP BY statement in MySQL is used to group rows that have the same values into summary rows. It is typically used with aggregate functions (such as COUNT(), SUM(), AVG(), MAX(), MIN()) to perform operations on each group of rows.

Example:

SELECT department_id, COUNT(*) AS employee_count
FROM employees
GROUP BY department_id;

This query calculates the number of employees in each department by grouping the rows based on the department ID and using the COUNT() aggregate function.

The GROUP BY statement is essential for performing aggregate operations on grouped data in MySQL.

Join the conversation