当前位置: 代码迷 >> ASP.NET >> 队列转求解
  详细解决方案

队列转求解

热度:3807   发布时间:2013-02-25 00:00:00.0
行列转求解
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

------解决方案--------------------------------------------------------
SQL code
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
------解决方案--------------------------------------------------------
探讨
SQL code


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……

------解决方案--------------------------------------------------------
解决了及时结贴啊
  相关解决方案