Sqlserver 列转行

来源:互联网 发布:为什么移民美国知乎 编辑:程序博客网 时间:2024/05/16 02:23

--创建表
create table #t(usser int ,no int ,a int,b int, c int)
insert into #t select 1,1,21,34,24
union all select 1,2,42,25,16

 

--列转行

SELECT usser,no,Type=attribute, Num=value
FROM #t
  UNPIVOT
  (
    value FOR attribute IN([a], [b], [c])
  ) AS UPV

原创粉丝点击