使用unpivot实现列转行
create table Fruit(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int); insert into Fruit values(1,'苹果',1000,2000,3300,5000); insert into Fruit values(2,'橘子',3000,3000,3200,1500); insert into Fruit values(3,'香蕉',2500,3500,2200,2500); insert into Fruit values(4,'葡萄',1500,2500,1200,3500); select * from Fruit; -- 列转行 select id, name, jidu, xiaoshou from Fruit unpivot (xiaoshou for jidu in (q1, q2, q3, q4));