I have an Oracle 11.2 table that looks like the following.
MSG_ID JOB_ID STATUS CREATION_DATE
1 101 SUB 03/30/2011 14:39:52
2 101 SUB 03/30/2011 14:44:37
3 101 RCVD 03/31/2011 14:41:49
4 101 ACCPTD 03/31/2011 14:59:51
5 101 DESIGN 03/31/2011 17:44:37
6 101 REVIEW 03/31/2011 17:44:50
7 101 (null) 04/01/2011 07:51:41
8 101 REJECTED 04/01/2011 07:56:56
9 101 (null) 04/01/2011 16:36:19
10 101 REVIEW 04/01/2011 16:43:49
11 101 APPROVED 04/04/2011 07:55:45
12 101 (null) 04/04/2011 08:14:23
13 101 REJECTED 04/04/2011 14:46:17
14 101 REVIEW 04/04/2011 14:50:50
15 101 (null) 04/04/2011 14:51:27
16 101 REVIEW 04/04/2011 14:57:50
17 101 (null) 04/04/2011 15:34:50
18 101 APPROVED 04/04/2011 15:41:21
19 101 (null) 04/04/2011 15:41:23
20 101 REJECTED 04/04/2011 15:41:24
21 101 REVIEW 04/04/2011 16:07:52
22 101 (null) 04/05/2011 08:50:35
23 101 APPROVED 04/05/2011 10:54:51
24 101 PROD 04/05/2011 11:08:50
25 101 COMPLET 04/06/2011 20:09:49
I am trying to group adjacent(with respect to creation date) message statuses and the time interval between each unique status combination. Null statuses can be ignored. The result would look like the following.
JOB_ID FROM_STATUS TO_STATUS TIME_INTERVAL
101 SUB RCVD sum of time intervals
101 RCVD ACCPTD sum of time intervals
101 ACCPTD DESIGN sum of time intervals
101 DESIGN REVIEW sum of time intervals
101 REVIEW REJECTED sum of time intervals
101 REJECTED REVIEW sum of time intervals
101 REVIEW APPROVED sum of time intervals
101 APPROVED REJECTED sum of time intervals
101 APPROVED PROD sum of time intervals
101 PROD COMPLETE sum of time intervals
Could someone help with the SQL needed to do this.
Thank you in advance