Home > database >  MySQL query comment on the largest number of 10 news
MySQL query comment on the largest number of 10 news

Time:09-17

Table 1, news news
Id number news
The content of news content
The title of news headline

2, review table, the comment
Comment id number
The content review
NewsId news number

Requirements:

Using MySQL query to comment on the largest number of 10 news

CodePudding user response:

Select top 10 Anderson d, a.c ontent, a.t itle, b.com _qty from news a, (select count (1) as com_qty, comment. NewsId from the comment group by the comment. NewsId) b where a.n ewsId=b.n ewsId order by b.com _qty desc

CodePudding user response:

I can't, error, and, within a b.com _qty! What's the meaning of

CodePudding user response:

Select *
The from
(select Anderson d, count (b.i d) as comment_cnt
The from
News as a
Inner join
The comment as b on Anderson, d=b.n ewsId
) as a
The order by comment_cnt desc
Limit 10

So try

CodePudding user response:

Fang Ling reference 3 floor is a little lovely reply:
select *
The from
(select Anderson d, count (b.i d) as comment_cnt
The from
News as a
Inner join
The comment as b on Anderson, d=b.n ewsId
) as a
The order by comment_cnt desc
Limit 10

So try



Select *
The from
(select Anderson d, count (b.i d) as comment_cnt
The from
News as a
Inner join
The comment as b on Anderson, d=b.n ewsId
Group by Anderson d
) as a
The order by comment_cnt desc
Limit 10

Every group by

CodePudding user response:

The select Anderson d, count (b.i d) as content_num
The from new as a
Inner join the content as on b (Anderson, d=b.n ewsld)
Group by Anderson d
The order by count (b.i d) desc
Limit 10
  • Related