sorry ,最后写错了一点
04      5
00      3
02      1
01      1上面的数据,02和01的位置不重要,因为它们记录数相同,请问这样的语句如何写呢

解决方案 »

  1.   

    select a.catid,isnull(b.num,0) num from category a left join (select left(artid,2) artid,count(*) num from articles group by left(artid,2)) b on a.catid=b.artid order by b.num
      

  2.   

    select a.catid,isnull(b.num,0) num from category a left join (select left(artid,2) artid,count(*) num from articles group by left(artid,2)) b on a.catid=b.artid order by b.num desc
      

  3.   

    select t1.catid, count(*)
      from category t1
      left join articles t2 on (t1.catid = SubString(t2.artid,1,2))
      group by t1.catid
      

  4.   

    select  left(artid ,2),count(*)
    from articles
    group by left(artid ,2)
      

  5.   

    你的意思是articles表的artid首两位统计:
    select a.* from
    (select  left(artid ,2) as artid,count(*) number
    from articles
    group by left(artid ,2)
    ) a
    order by number desc
      

  6.   

    select  left(artid,2),count(*) from articles group by left(artid,2)
      

  7.   

    select a.* from
    (select  left(artid ,2) as artid,count(*) number
    from articles
    group by left(artid ,2)
    ) a
    where number>0
    order by number desc
      

  8.   

    select  left(artid,2),count(*) from articles group by left(artid,2) order by count(*) desc
      

  9.   

    select  left(artid,2),count(*) from articles group by left(artid,2) having count(*) > 0
      

  10.   

    select  left(artid,2),count(*) from articles group by left(artid,2) having count(*)>0 order by count(*) desc