Home  >  Article  >  Database  >  How to count the number of groups in mysql

How to count the number of groups in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-10-28 15:19:1013477browse

Mysql method to count the number of groups: 1. Count the total number of records [SELECT count(*) FROM table name WHERE condition]; 2. Count the number of records in each group [SELECT count(*) FROM table name WHERE condition GROUP BY id].

How to count the number of groups in mysql

Mysql method of counting the number of groups:

SELECT count(*) FROM 表名 WHERE 条件

What is found is the total number of records

SELECT count(*) FROM 表名 WHERE 条件 GROUP BY id

The statistics will be the number of records in each group.

How to get the total number of records in the second sql statement?

It is as follows :  

select count(*) from(SELECT count(*) FROM 表名 WHERE 条件 GROUP BY id ) a ;
SELECT count(*) FROM (SELECT COUNT(*) FROM `papa_stadium_goods_storage_record` WHERE `c_time`>=1474560000 and `c_time`<1476201600 group by `record_type`) a

Note:

In the subquery method, aliases must be used for the subresult set in MySQL, but there is no need to add aliases specifically in Oracle!

More related free learning recommendations: mysql tutorial(Video)

The above is the detailed content of How to count the number of groups in mysql. 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