我看懂了oracle中pivot行转列的用法
我看懂了PIVOT的用法
用法Select * From 表名,
PIVOT
(
SUM('要合并的列1'),MAX('要合并的列2'),....FOR 将值转换成列的列名 IN
(列名1,列名2,列名3,列名4....)
)
从用法中可以看出sum,max是配合PIVOT聚合函数,聚合函数必须要有。
实际用例:
select *
from (
select ID,
Type,
parameter,
value,
machine_no,
Operator,
update_time
from tableName)
pivot(
max(value) as value,
max(machine_no) as machine_no,
max(Operator) as Operator,
max(update_time) as update_time
for parameter in(
'before' as Before,
'after' as After,
'delta' as Delta,
'airbag' as AirBag )
)
where ID= '111111111111'
在转换过程中生成的新列名是由上面红色字组合成的,生成的新列数为4*4=16列。例:Before_Value Before_Machine_No,Before_Operator
来自:https://www.cnblogs.com/zhubin1314521/p/3770712.html
本文来自博客园,作者: 三生有幸格格,转载请注明原文链接:https://www.cnblogs.com/mylive/p/16225505.html