create table #tb(name varchar(32),kechen varchar(32),score float); insert into #tb values('小明','数学',99) insert into #tb values('小明','英语',60) insert into #tb values('小明','语文',100) insert into #tb values('小强','数学',29) insert into #tb values('小强','语文',130) --行转列 select * from #tb pivot(sum(score)for kechen in([数学],[英语],[语文]))a --列转行 select * from #tb1 unpivot(score for kechen in ([数学],[英语],[语文])) a