日期:2014-05-19  浏览次数:20476 次

求1SELECT语句,立刻结帖.
货运公司       送货人
DHL                 LJM
UPS                 TJS
DHL                 SJ
UPS                 LHH
DHL                 GTM
...
----------------------
怎样得到以下结果.
----------------------
货运公司       出现率
DHL                 3
UPS                 2
...

------解决方案--------------------
select 货运公司,[出现率]=count(*)
from table1 group by 货运公司
------解决方案--------------------
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

------解决方案--------------------
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 chinaooooo2008

group by 货运公司


-----------------

货运公司

DHL 3
UPS 2