GROUP BY Clause MYSQL

The GROUP BY statement groups rows that have the same values into summary rows, like “find the number of customers in each country”.

The GROUP BY statement is often used with aggregate functions (COUNT, MAX, MIN, SUM, AVG) to group the result-set by one or more columns.


Syntax:

SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);

Query:

SELECT count(emp_no),year(hire_date) FROM `employees` group by year(hire_date)


Output
:

Group By Clause Example

As you can see number of employees hired are calculated based on the years

Tester Usage Tips:

  • Validate summary of group of records like no of students passed year wise