Home > Backend Development > PHP Tutorial > How to count the number of people in each province using a SQL statement

How to count the number of people in each province using a SQL statement

WBOY
Release: 2023-03-02 09:22:02
Original
3514 people have browsed it

There is a Mysql data table to record customer information
id name province
1 Zhang San Beijing
2 Li Si Beijing
3 Wang Er Hebei
4 Zhao Feng Hebei
5 Liu Fei Hebei
6 Jia You Hubei
7 Zhu Tao Hunan
How about Use SQL to find the number of people in each province?
SELECT COUNT(PROVINCE) FROM TABLE GROUP BY PROVINCE OK?
How to display it using PHP?

Reply content:

There is a Mysql data table to record customer information
id name province
1 Zhang San Beijing
2 Li Si Beijing
3 Wang Er Hebei
4 Zhao Feng Hebei
5 Liu Fei Hebei
6 Jia You Hubei
7 Zhu Tao Hunan
How about Use SQL to find the number of people in each province?
SELECT COUNT(PROVINCE) FROM TABLE GROUP BY PROVINCE OK?
How to display it using PHP?

<code>SELECT province, COUNT( province ) 
FROM test
GROUP BY province</code>
Copy after login

How to count the number of people in each province using a SQL statement

Yes. Take out the data set upstairs. Just use foreach to iterate over it

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