Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

I need help with a query

user8632367Aug 29 2013 — edited Aug 29 2013

Hello everyone,

First, some background information.  We have in place a table which records status changes on a work order.  The orders normally go through each status only once, however they do occasionally reuse status indicators.  For example, an order is placed on hold, released from hold, placed back on hold, released again and so on.  The sample data provided is an example of an order with data repeating itself.  I need some help with writing a query on this table.

LOC_CODEWO_NOUPDATETIMEWO_STATUS_OLDWO_STATUS_NEW
xxx1234505-01-2013 10:24:00WRSP
xxx1234505-01-2013 10:39:00SPPM
xxx1234505-01-2013 11:52:00PMES
xxx1234505-01-2013 11:58:00ESMO
xxx1234505-01-2013 12:03:00MOES
xxx1234505-01-2013 12:38:00ESAT
xxx1234505-01-2013 12:48:00ATRS
xxx1234505-01-2013 13:01:00RSRA
xxx1234505-01-2013 13:26:00RARS
xxx1234505-01-2013 13:36:00RSRA
xxx1234505-01-2013 15:35:00RARS
xxx1234505-01-2013 15:42:00RSRA
xxx1234505-01-2013 16:04:00RARS
xxx1234505-01-2013 16:42:00RSRA
xxx1234505-01-2013 19:28:00RAFD
xxx1234505-01-2013 19:28:00FDSO

The query (which will in turn be used for a view) will display the elapsed time between status updates (subtract updatetime from the record preceeding).  Only the first record for each order at a location would have no elapsed time.  The result should look like this:

LOC_CODEWO_NOUPDATETIMEWO_STATUS_OLDWO_STATUS_NEWMINUTES_ELAPSED
xxx1234505-01-2013 10:24:00WRSP{null}
xxx1234505-01-2013 10:39:00SPPM

15

xxx1234505-01-2013 11:52:00PMES73
xxx1234505-01-2013 11:58:00ESMO6
xxx1234505-01-2013 12:03:00MOES5
xxx1234505-01-2013 12:38:00ESAT35
xxx1234505-01-2013 12:48:00ATRS10
xxx1234505-01-2013 13:01:00RSRA13
xxx1234505-01-2013 13:26:00RARS25
xxx1234505-01-2013 13:36:00RSRA10
xxx1234505-01-2013 15:35:00RARS119
xxx1234505-01-2013 15:42:00RSRA7
xxx1234505-01-2013 16:04:00RARS22
xxx1234505-01-2013 16:42:00RSRA38
xxx1234505-01-2013 19:28:00RAFD166
xxx1234505-01-2013 19:28:00FDSO0

I have been trying various queries, but no luck as of yet.  I would appreciate your input.

Thank you,

Patrick

This post has been answered by Frank Kulash on Aug 29 2013
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 26 2013
Added on Aug 29 2013
3 comments
238 views