货运公司 送货人
DHL LJM
UPS TJS
DHL SJ
UPS LHH
DHL GTM
...
----------------------
怎样得到以下结果.
----------------------
货运公司 出现率
DHL 3
UPS 2
...
DHL LJM
UPS TJS
DHL SJ
UPS LHH
DHL GTM
...
----------------------
怎样得到以下结果.
----------------------
货运公司 出现率
DHL 3
UPS 2
...
from table1 group by 货运公司
from tb group by 货运公司
from 表名
group by 货运公司
(货运公司 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
(货运公司 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
select 货运公司,count(1) as 出现率 from chinaooooo2008group by 货运公司 order by 出现率 desc