Oracle 行转列 测试例子

 关键点 是 要使用分组函数 和 判断

select FACTORYNAME,WORKCENTER,OPERATION,RESOURCEGROUPNAME,RESOURCENAME,OUTPUTQTY, 
to_char(max(DECODE(Status,'Idle',timepercent,'0.0%'))) as Idle,
max(DECODE(Status,'Down',timepercent,'0.0%')) as Down,
max(DECODE(Status,'Run',timepercent,'0.0%')) as Run,
max(DECODE(Status,'Offline',timepercent,'0.0%')) as Offline1
 from
(
 
) t
group by FACTORYNAME,WORKCENTER,OPERATION,RESOURCEGROUPNAME,RESOURCENAME,OUTPUTQTY

你可能感兴趣的:(ORACLE)