行列转换 create table test(
id int ,
name char(2),
quarter int ,
profile int
)
insert into test
select 1,'a',1,1000
union all select 1,'a',2,2000
union all select 1,'a',3,3000
union all select 1,'a',4,4000
union all select 2,'b',1,3500
union all select 2,'b',2,3000
union all select 2,'b',3,4500
union all select 2,'b',4,5000
select * from test;
select id,name,1 as "一季度",2 as "er季度",3 as "sav季度",4 as "si季度"
from test
pivot (
sum(profile)
for quarter
in ([1],[2],[3],[4])
)
as pvt