SQL PIVOT关键字例

来源:互联网 发布:php hls流媒体 编辑:程序博客网 时间:2024/06/05 06:48
select *from(select Col1,Col2,Value from Result) as t1


Col1  |  Col2| Value

a         5 1
a         4 -1
b         5 3
b         4 4
c         5 1
c         4 -1

a         5 1

a         6 1

select *from(select Col1,Col2,Value from Result) as t1pivot( avg(Value) for [Col1] in (a,b,c,d) )as t2

Col1  a   b      c       d

4 -1 4 -1 NULL
5 1 31NULL
6 1 NULLNULLNULL


原创粉丝点击