SQL代码如下:将列转行SELECT Cs_ID, MoneyType, MoneyAmount
FROM Omc_CostsSubmitted
UNPIVOT (
MoneyAmount FOR MoneyType IN
(Cs_TotalPrice, Cs_ApplicationPrice_1, Cs_ApplicationPrice_2, Cs_ApplicationPrice_3,Cs_ApplicationPrice_4)
) as A效果图如下在线等啊 怎么创建这样的视图
FROM Omc_CostsSubmitted
UNPIVOT (
MoneyAmount FOR MoneyType IN
(Cs_TotalPrice, Cs_ApplicationPrice_1, Cs_ApplicationPrice_2, Cs_ApplicationPrice_3,Cs_ApplicationPrice_4)
) as A效果图如下在线等啊 怎么创建这样的视图
create table test(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int)
insert into test values(1,'a',1000,2000,4000,5000)
insert into test values(2,'b',3000,3500,4200,5500)
select id,name,quarter,profile
from
test
unpivot
(
profile
for quarter in
([Q1],[Q2],[Q3],[Q4])
)
as unpvt
http://topic.csdn.net/u/20090806/21/91dfb66a-55e2-4a94-a986-182c2c6a8251.html