--创建表
create table T (Providerid int ,Product varchar(12),Price int)
insert T select
1, '1商品1',12 union select
1, '1商品2',145 union select
1, '1商品3',19 union select
2, '2商品1',100 union select
2, '2商品2', 200 union select
3, '3商品5',400
/***************************************************************/select ProviderId,
max(case product when '1商品1' then Price else '' end) [1商品1],
max(case product when '1商品2' then Price else '' end) [1商品2],
max(case product when '1商品3' then Price else '' end) [1商品3],
max(case product when '2商品1' then Price else '' end) [2商品1],
max(case product when '2商品2' then Price else '' end) [2商品2],
max(case product when '3商品5' then Price else '' end) [3商品5]
from T group by ProviderId
/***************************************************************/select ProviderId,
max(case product when '1商品1' then Price else '' end) '1商品1',
max(case product when '1商品2' then Price else '' end) as '1商品2',
max(case product when '1商品3' then Price else '' end) as '1商品3',
max(case product when '2商品1' then Price else '' end) as '2商品1',
max(case product when '2商品2' then Price else '' end) '2商品2',
max(case product when '3商品5' then Price else '' end) as '3商品5'
from T group by ProviderId问题:比较两个执行语句中,[]和’’的区别?
create table T (Providerid int ,Product varchar(12),Price int)
insert T select
1, '1商品1',12 union select
1, '1商品2',145 union select
1, '1商品3',19 union select
2, '2商品1',100 union select
2, '2商品2', 200 union select
3, '3商品5',400
/***************************************************************/select ProviderId,
max(case product when '1商品1' then Price else '' end) [1商品1],
max(case product when '1商品2' then Price else '' end) [1商品2],
max(case product when '1商品3' then Price else '' end) [1商品3],
max(case product when '2商品1' then Price else '' end) [2商品1],
max(case product when '2商品2' then Price else '' end) [2商品2],
max(case product when '3商品5' then Price else '' end) [3商品5]
from T group by ProviderId
/***************************************************************/select ProviderId,
max(case product when '1商品1' then Price else '' end) '1商品1',
max(case product when '1商品2' then Price else '' end) as '1商品2',
max(case product when '1商品3' then Price else '' end) as '1商品3',
max(case product when '2商品1' then Price else '' end) as '2商品1',
max(case product when '2商品2' then Price else '' end) '2商品2',
max(case product when '3商品5' then Price else '' end) as '3商品5'
from T group by ProviderId问题:比较两个执行语句中,[]和’’的区别?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货