我不擅长数据库查询。需要帮助可能是一个简单的查询。
数据库:MYSQL
zip | city | state
post_id | title | post | zip
我需要显示每个独特城市的帖子数量。
答案 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;