Home  >  Article  >  Backend Development  >  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
WBOYOriginal
2016-12-01 00:57:103500browse

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>

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

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