Sql语句查询问题,如何将横排的数据变为竖排
表APartNOYearJanFebMarAprP0012012120304050变成PartNOYearMonthQTYP0012012Jan120P0012012Fe...
表A
PartNO Year Jan Feb Mar Apr
P001 2012 120 30 40 50
变成
PartNO Year Month QTY
P001 2012 Jan 120
P001 2012 Feb 30
P001 2012 Mar 40
P001 2012 Apr 50 展开
PartNO Year Jan Feb Mar Apr
P001 2012 120 30 40 50
变成
PartNO Year Month QTY
P001 2012 Jan 120
P001 2012 Feb 30
P001 2012 Mar 40
P001 2012 Apr 50 展开
2个回答
展开全部
select*from
(
select PartNO , Year,Month='Jan' , Result = Jan from tb1
unionall
select PartNO , Year,Month ='Feb' , Result = Feb from tb1
unionall
select PartNO , Year,Month='Mar' , Result = Mar from tb1
) t
orderby PartNO, case Month when'Jan' then1when'Feb'then 2 when'Mar' then3 end
(
select PartNO , Year,Month='Jan' , Result = Jan from tb1
unionall
select PartNO , Year,Month ='Feb' , Result = Feb from tb1
unionall
select PartNO , Year,Month='Mar' , Result = Mar from tb1
) t
orderby PartNO, case Month when'Jan' then1when'Feb'then 2 when'Mar' then3 end
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你在百度搜索行列转化 会有很多实例,你看着改就行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询