select
    a.*
from
    a
order by
    isnull((select count(*) from b where newsid=a.id),0) desc,a.posttime

解决方案 »

  1.   

    按评论数顺序排列:select
        a.*
    from
        a
    order by
        isnull((select count(*) from b where newsid=a.id),0),a.posttime
      

  2.   

    select a.* from 表a 
    inner join (select newsid,count(comment) as countcom from 表b) b
    order by b.countcom,a.posttime
      

  3.   

    select a.* from 表a 
    inner join (select newsid,count(comment) as countcom from 表b where b.newsid=a.id) b
    order by b.countcom,a.posttime