Home>Article>Database> How to count the number of records after MySQL grouping

How to count the number of records after MySQL grouping

coldplay.xixi
coldplay.xixi Original
2020-10-23 15:55:23 6437browse

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.

How to count the number of records after MySQL grouping

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:

How to count the number of records after MySQL grouping

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

How to count the number of records after MySQL grouping

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn