GROUP BY Clause

Purpose: The GROUP BY clause groups rows that have the same values in specified columns into summary rows, often used with aggregate functions.Syntax:

GROUP BY column1, column2, ...;

Example:

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

Explanation: This counts the number of employees in each department, returning one row per department.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *