我需要一些帮助才能获得评论最多的帖子。有 2 个表,一个有帖子 web_content,另一个表有评论 web_jcomments。
我需要获得评论最多的帖子和评论的数量。web_content.ID = web_jcomments.object_id。数据库在 MYSQL 中。
请问有人可以帮助SQL代码吗?感谢您阅读
SELECT
wc.ID,
wj.Total
FROM web_content as wc
LEFT JOIN (
SELECT
object_id,
count(object_id) as Total
) as wj on wc.ID = wj.object_id
ORDER BY wi.Total DESC
很久没写MySQL了。。
就像是:
SELECT
web_content.ID,
COUNT(*)
FROM web_content.ID
LEFT JOIN web_jcomments ON (web_content.ID = web_jcomments.object_id)