首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求1SELECT语句,立刻结帖.解决方法

2012-02-28 
求1SELECT语句,立刻结帖.货运公司送货人DHLLJMUPSTJSDHLSJUPSLHHDHLGTM...----------------------怎样得到

求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

热点排行