The GROUP BY
clause in SQL is used to group rows that have the same values in specified columns into summary rows, such as counts, sums, or averages.
Syntax
SELECT column1, aggregate_function(column2)
FROM table_name
GROUP BY column1;
Example
SELECT department, COUNT(*)
FROM employees
GROUP BY department;
This query counts the number of employees in each department.
The GROUP BY
clause in SQL is essential for data aggregation, allowing you to summarize and analyze data by grouping rows based on specified columns.