MySQL查询帮助

时间:2009-10-14 12:25:07

标签: mysql

我不擅长数据库查询。需要帮助可能是一个简单的查询。

数据库:MYSQL

zipcodes [table]

zip | city | state

post [table]

post_id | title | post | zip

我需要显示每个独特城市的帖子数量。

2 个答案:

答案 0 :(得分:3)

SELECT count(*) FROM post LEFT JOIN zipcodes ON post.zip = zipcodes.zip GROUP BY city;

答案 1 :(得分:0)

我会这样做。这样会在输出中显示城市名称,并显示没有帖子的城市。

SELECT city,count(*) as "num_posts" FROM zipcodes LEFT JOIN post ON post.zip = zipcodes.zip GROUP BY city;