Mysql statistical problem

city
id name

1 Beijing
2 Shanghai
3 Tianjin

news Newslist
id name city
1 my 1
2 my 2
3 my 2
4 my 3

find out

how many messages are there in Beijing
how many messages are there in Shanghai
how many messages are there in Tianjin

Mar.18,2021

< H2 > do your homework by yourself < / H2 >

SQL join is used to query data from two or more tables based on the relationship between the columns in those tables.
http://www.w3school.com.cn/sq.
hint: the id of the city table needs to correspond to the city of the news table

SQL group by is used to combine aggregate functions to group result sets according to one or more columns.
http://www.w3school.com.cn/sq.
hint: need to group by city

SQL count returns the number of rows selected in a given selection.
http://www.w3school.com.cn/sq.
hint: it's OK to use count (1), but the speed will be slightly faster

.

city table redundant one field record common number of entries num, but every time there is new or deleted data, you need to maintain the field. The advantage is that there is no need to make a correlation in statistics, and it can be obtained directly.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e54e6b-452e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e54e6b-452e7.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?