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].
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!