MySQL group query and count the SQL statements greater than a certain value

created at 07-27-2021 views: 2

Table data

Statistical data sql statement

SELECT name,count(*) FROM `test` GROUP BY name;

Data result

Sort after statistics

SELECT name,count(*) as count FROM `test` GROUP BY name ORDER BY -name;

Filter data greater than 2 after statistics

SELECT name,count(*) as count FROM `test` GROUP BY name HAVING count>2

reasons for using having

The HAVING clause is usually used together with the GROUP BY clause to filter groups according to specified conditions. If the GROUP BY clause is omitted, the behavior of the HAVING clause is similar to that of the WHERE clause.

created at:07-27-2021
edited at: 07-27-2021: