events表有一个名为“city_id”的列。我希望看到像这样的结果
Miami 30
Tampa 11
San Franciso 29
我正在使用mysql。
答案 0 :(得分:0)
INNER JOIN,GROUP BY,COUNT ......这很有可能只需要你做这个简单的查询!
答案 1 :(得分:0)
这样的事情会帮助你
SELECT
city_id,
max(city_name),
count(*)
FROM events
GROUP BY
city_id
答案 2 :(得分:0)
假设您在另一个表中有城市名称
select e.city_id, c.name, count(*) eventcount
from events e
join city c on c.id = e.city_id
group by e.city_id, c.name