问题描述
表message结构如下:id:文章idtitle:标题content:内容hits:点击率表comment结构如下:cid:留言idmid:对应message文章idccon:留言内容现在通过查询数据库得到下面结果(并按照回复数量排序,回复数量最多的在前面)。结果如下:文章id 文章标题 文章点击率 文章回复数量用一条sql语句完成上面查询,如果文章没有回复则回复数量为0
解决方案
select id, title, hits, count(mid) from message left join comm on message.id=comm.mid(+) group by id, title, hits;
解决方案二:
select id,title, hits,a.chits from message left join (select mid,count(mid) as chits from comment grounp by mid) aon id=a.mid 试一下,没有测 不好意思
时间: 2025-01-15 16:10:36