SQL Practice Logo

SQLPractice Online

GROUP BY Fundamentals: Interview

Module: Aggregate Functions & Grouping

What does GROUP BY do?

GROUP BY groups rows with same values into summary rows, enabling aggregates per group instead of entire table.

Can you select non-grouped columns?

No, all non-aggregate columns in SELECT must appear in GROUP BY clause.

Group employees by department and calculate average salary

SELECT department, AVG(salary) AS avg_salary FROM employees GROUP BY department;

Creates one row per department with average salary for that department.