SQL行列转换--UNPIVOT

create table a
(
	id int identity(1,1),
	area varchar(20),
	da1 int,
	da2 int,
	da3 int,
	db1 int,
	db2 int,
	db3 int
	
)

insert into a values ('北京',1,2,3,4,5,6)
insert into a values ('上海',7,8,9,10,11,12)

select * from a unpivot(num for Cols in (da1,da2,da3,db1,db2,db3)) a 

drop table a

  

你可能感兴趣的:(行列转换)