GROUP BY SQL query to get number of records, average , maximum minimum & sum over a group of records

preview_player
Показать описание

By using group by query we can use aggregate functions like count(), max(), min() , avg() , sum() to get data over a group of records.
command will create groups in the field name specified and will count the number
of records in the groups.
SELECT count(*) as total_records, class FROM `student` group by class

We can also use WHERE command along with GROUP BY command in Mysql tables.

SELECT class,count( * ) AS total_records FROM `student` WHERE gender='female' GROUP BY class
We can find out duplicate records in a table by using group by command.
SELECT name, COUNT(id) AS no from student2_1 group by name having no greate than 1
Рекомендации по теме