Home > Database > Mysql Tutorial > body text

How to count the number of groups in mysql

coldplay.xixi
Release: 2020-10-29 16:21:56
Original
13479 people have browsed it

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 条件
Copy after login

What is found is the total number of records

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

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 ;
Copy after login
SELECT count(*) FROM (SELECT COUNT(*) FROM `papa_stadium_goods_storage_record` WHERE `c_time`>=1474560000 and `c_time`<1476201600 group by `record_type`) a
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template