按照文章评论数量的多少排序输出文章列表 评论数量多的最先输出a表 是文章表 字段 a_id,a_title,a_textb表是评论表字段 b_id,b_pid(存储a表的id,也就是评论所属的文章id),b_comment求能够实现改功能的mysql查询语句

解决方案 »

  1.   

    SELECT a.id, a.title
    FROM a, b
    WHERE a.id = b.p_id
    GROUP BY a.id, a.title
    ORDER BY sum( b.id ) desc
    LIMIT 0 , 30 
    字段对应着看看吧,可能和你的有些区别。
      

  2.   

    不能编辑,只能连续回复了。SELECT a.id, a.title,count( b.id ) 
    FROM a, b
    WHERE a.id = b.p_id
    GROUP BY a.id, a.title
    ORDER BY count( b.id ) DESC 
    LIMIT 0 , 30 
      

  3.   

    SELECT  a_id, a_title ,COUNT(b_id) AS ncount,
    FROM b LEFT JOIN a ON a.a_id = b.b_pid
    GROUP BY b.b_pid
    ORDER BY ncount desc
      

  4.   

    SELECT count( b.p_id ) pcount, a.a_id,a.a_title,a.a_text  
    FROM a, b 
    WHERE a.a_id= b.b_pid 
    GROUP BY a_id 
    HAVING count( a.a_id ) >=0 
    ORDER BY pcount DESC
      

  5.   

    select a.a_id,a.a_title,count(b.b_pid) as b_count
    from b left join a on b.b_pid=a.a_id
    groub by b_pid
    order by b_count desc
    limit 0,30;
     
      

  6.   

    SELECT count( b.p_id ) pcount, a.a_id,a.a_title,a.a_text  
    FROM a, b 
    WHERE a.a_id= b.b_pid 
    GROUP BY a_id 
    ORDER BY pcount DESC
      

  7.   

    select a.a_id,a.a_title,count(b.b_pid) as b_count 
    from b left join a on b.b_pid=a.a_id 
    group by b_pid 
    order by b_count desc 
    limit 0,30;