让我说我有:
SELECT bloggers.*,
COUNT(post_id) AS post_count
FROM bloggers
LEFT JOIN blogger_posts ON bloggers.blogger_id = blogger_posts.blogger_id
GROUP BY bloggers.blogger_id
ORDER BY post_count
返回按帖子计数排序的所有博主。 如果我只想要一些博客但按照相同标准排序(例如那些AUX字段等于3的那些博客)怎么办?
答案 0 :(得分:4)
WHERE
子句应紧接在GROUP BY
子句之前。如果对语法的简单性有疑问,那么看的地方就是手册。
SELECT bloggers.*,
COUNT(post_id) AS post_count
FROM bloggers
LEFT JOIN blogger_posts ON bloggers.blogger_id = blogger_posts.blogger_id
WHERE bloggers.AUX = 3
GROUP BY bloggers.blogger_id
ORDER BY post_count