某CMS中,文章表news和評論表comment字段如下: 文章表news 評論表comment id文章id主鍵 ID評論id主鍵自增 title文章標題 news_id關(guān)聯(lián)文章表id content文章內(nèi)容 status審核狀態(tài) 0審核 1審核通過 hits點擊量 content評論內(nèi)容 created_time發(fā)布時間戳 created_time發(fā)布時間戳 updated_time最后修改時間戳1.文章排行榜頁面需要展示一下數(shù)據(jù)文章id 文章標題 點擊量 評論量要求按照當天的評論數(shù)量倒序排列 取前十名。評論數(shù)相同則取較新的文章,沒有評論則評論數(shù)量顯示為0用一條sql語句完成上述查詢
1 回答

慕田峪7331174
TA貢獻1828條經(jīng)驗 獲得超13個贊
select a.*,t.c from news a inner join (select count(1) as c,news_id from comment group by news_id having count(1)>0 order by count(1) desc limit 10) t on a.id=t.news_id order by t.c desc,a.create_time desc;
添加回答
舉報
0/150
提交
取消