当前位置: 代码迷 >> Oracle开发 >> ,请问单表分组输出有关问题
  详细解决方案

,请问单表分组输出有关问题

热度:64   发布时间:2016-04-24 06:42:53.0
在线等,请教单表分组输出问题
现在有一表数据如下:
SERIAL_NUMBER          PROCESS_NAME                 OUT_TIME
DYH0100055054414   BV Check Rework Output    2014/5/16 16:19
DYH0100055054414   BV Check Rework Input       2014/5/16 18:52
DYH0100055063483   BV Check Rework Input       2014/5/16 18:45
DYH0100055063483   BV Check Rework Output    2014/5/16 14:19
DYH0100055063596   BV Check Rework Output    2014/5/16 19:12
DYH0100055064931   BV Check Rework Input       2014/5/16 9:33

希望出来的数据格式如下
SERIAL_NUMBER          BV Check Rework Output    BV Check Rework Input
DYH0100055054414        2014/5/16 16:19                  2014/5/16 18:52
DYH0100055063483        2014/5/16 14:19                  2014/5/16 18:45 
DYH0100055063596        2014/5/16 19:12
DYH0100055064931                                                    2014/5/16 9:33

以SERIAL_NUMBER 为唯一条件,把Output和Input时间列在SERIAL_NUMBER之后,成一列。
对应一条SERIAL_NUMBER的Output或者Input时间不存在就为空。请高手指点下。多谢!
------解决方案--------------------
select SERIAL_NUMBER,max(case PROCESS_NAME when 'BV Check Rework Output' then  OUT_TIME end) "BV Check Rework Output",
max(case PROCESS_NAME when 'BV Check Rework Input' then  OUT_TIME end) "BV Check Rework Input"
from t
group by SERIAL_NUMBER
  相关解决方案