select  departname,count(1) from articles
group by departname

解决方案 »

  1.   

    select  departname,count(1) as 数量 from articles
    group by departname
      

  2.   

    select departname,count(*) from articles group by departname order by count(*) Desc
      

  3.   

    declare @articles table (id int,author varchar(10),departname varchar(20),title varchar(20))
    insert into @articles
    select 1,'zzk','總公司','內容' union all 
    select 2,'lyb','分公司1','內容' union all 
    select 3,'zzk','總公司','內容' union all 
    select 4,'kk','分公司2','內容' union all 
    select 5,'ll','分公司1','內容' union all 
    select 6,'zzk','總公司','內容'  select departname,count(departname) as 數量 
    from @articles
    group by departname
    order by count(departname) desc
    結果:
    departname           數量          
    -------------------- ----------- 
    總公司                  3
    分公司1                 2
    分公司2                 1
      

  4.   

    select departname,count(1) from articles group by departname order by count(1) Desc