Home > Article > Backend Development > How to count the number of people in each province using a SQL statement
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?
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>
Yes. Take out the data set upstairs. Just use foreach
to iterate over it