货运公司   送货人
DHL        LJM
UPS        TJS
DHL        SJ
UPS        LHH
DHL        GTM
...
----------------------
怎样得到以下结果.
----------------------
货运公司   出现率
DHL        3
UPS        2
...

解决方案 »

  1.   

    select 货运公司,[出现率]=count(*)
    from table1 group by 货运公司
      

  2.   

    select 货运公司,count(*) as 出现率
    from tb group by 货运公司
      

  3.   

    select 货运公司,[出现率]=count(*)
    from 表名
    group by 货运公司
      

  4.   

    create table  #t3
    (货运公司 varchar(50),
    送货人 varchar(50)
    )
    insert into  #t3
    select 'DHL','LJM' union all select 'UPS','TJS' union all select 'DHL','SJ' union all select 'UPS','LHH' union all select 'DHL','GTM'
    select * from  #t3
    select 货运公司,count(distinct 送货人) 出现次数
    from #t3 
    group by 货运公司
    --------------------
    DHL   3
    UPS   2
      

  5.   

    create table  chinaooooo2008 
    (货运公司 varchar(50),
    送货人 varchar(50)
    )insert into chinaooooo2008 
    select 'DHL'     ,  'LJM' union all
    select'UPS '   ,    'TJS'union all
    select'DHL'    ,    'SJ'union all
    select'UPS'   ,     'LHH'union all
    select'DHL'   ,     'GTM'
    select 货运公司,count(1) from chinaooooo2008group by 货运公司
    -----------------货运公司  DHL   3
    UPS   2
      

  6.   


    select 货运公司,count(1)  as 出现率 from chinaooooo2008group by 货运公司 order by 出现率 desc