After MySQL is grouped, the method of counting the number of records: 1. Count the number of records, the code is [SELECT num, count(*) AS counts from test_a GROUP BY num]; 2. After deduplication of num Quantity statistics.
MySQL method to count the number of records after grouping:
After grouping, count the number of records Number:
SELECT num,count(*) AS counts from test_a GROUP BY num;
The query results are as follows:
Statistics on the number of num after deduplication:
SELECT count(t.counts) FROM ( SELECT num,count(*) AS counts from test_a GROUP BY num ) AS t; SELECT count(DISTINCT num) AS count FROM test_a;
The two results are the same, both are 5; except that one is a subquery (nested) and the other is the built-in function distinct();
Database structure
More related free learning recommendations:mysql tutorial(Video)
The above is the detailed content of How to count the number of records after MySQL grouping. For more information, please follow other related articles on the PHP Chinese website!