在同一个表+ oracle中连接行

时间:2012-08-10 09:10:38

标签: oracle

  I have a table MNO like this:-



 key    open  mode  close     time
   1    112    O             10:15pm
   1           C     200     11:50pm

我想查询输出给我这个: -

key  open   close   difference  open_time   close_time
1    112     200      88         10:15pm      11:50pm

1 个答案:

答案 0 :(得分:2)

select
 o.key, o.open, c.close, 
 c.close - o.open as difference,
 o.time as open_time,
 c.time as close_time
from 
  mno o
  mno c
where
  o.key = c.key
and o.mode='O'
and c.mode='C'
;