行列转求解
set nocount on
declare @tt table
(
Months varchar(10),
Shop_Code varchar(500),
sale_Amount varchar(50)
)
insert into @tt select '[1月]','P000349','47950'
insert into @tt select '[2月]','P000055','54520'
insert into @tt select '[2月]','P000007','58020'
insert into @tt select '[2月]','P000349','58119'
insert into @tt select '[3月]','P000055','7045'
insert into @tt select '[3月]','P000039','0'
insert into @tt select '[3月]','P000348','34156'
insert into @tt select '[4月]','P000039','67030'
insert into @tt select '[5月]','P000039','53700'
select * from @tt
[解决办法]
select Shop_Code 产品代码, max(case Months when '[1月]' then sale_Amount else 0 end) 一月, max(case Months when '[2月]' then sale_Amount else 0 end) 二月, max(case Months when '[3月]' then sale_Amount else 0 end) 三月, max(case Months when '[4月]' then sale_Amount else 0 end) 四月, max(case Months when '[5月]' then sale_Amount else 0 end) 五月from @tt group by Shop_Code
[解决办法]