我需要一些帮助来获得评论最多的帖子。 有2个表,一个有帖子web_content,另一个表有评论web_jcomments。
我需要获得评论最多的帖子和评论数量。 web_content.ID = web_jcomments.object_id。 数据库是MYSQL。
请问有人可以帮助SQL代码吗? 感谢您阅读
答案 0 :(得分:1)
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
答案 1 :(得分:0)
自从我写MySQL以来已经很久了..
类似的东西:
SELECT
web_content.ID,
COUNT(*)
FROM web_content.ID
LEFT JOIN web_jcomments ON (web_content.ID = web_jcomments.object_id)