I have a table tickets with ticketid,owner, owndate
columns. The table is as..
ticketid owner ownerdate
1001 LEWIS 2004-06-18 14:15:11
1001 WILSON 2004-06-18 14:16:54
1001 WILSON 2004-06-18 14:21:12
1001 (null) 2004-09-01 09:56:11
1001 CALDONE 2005-02-02 08:38:28
1001 SINCLAIR 2005-02-02 08:54:02
1002 (null) 2005-02-02 08:40:06
1002 REID 2015-01-16 15:18:05
1002 SMALL 2015-01-16 15:19:53
1002 WILSON 2004-06-18 14:33:47
1002 (null) 2004-08-31 15:12:46
1002 (null) 2004-09-24 10:03:09
1003 RAMSDALE 2004-09-24 10:04:24
1003 MOTIKA 2004-08-31 14:51:45
1003 (null) 2004-08-31 15:05:50
1003 MURTHY 2004-09-02 14:50:28
1004 (null) 2004-08-31 15:28:37
1004 (null) 2004-09-24 09:24:21
1005 MOTIKA 2004-08-31 14:47:19
1005 MOTIKA 2004-08-31 17:20:33
1005 (null) 2004-08-31 17:23:42
1005 WILSON 2004-09-02 16:29:43
1005 DALEY 2004-09-15 08:45:27
1005 SINCLAIR 2004-09-15 08:34:34
1006 REID 2004-09-15 08:44:16
I need the output as…
ticketid timediff1 timeidff2 timediff3 ...
1001 1 min 43 sec 4min 18 6 min 1sec ...
... ... ... ...
Here the timediff1 is the time difference for any distinct ticket id for owner1 and timediff2 is time difference for 2nd owner and so on.
Best Answer
This is a lot of code with tables selecting on tables and a dynamic pivot statement at the end. Let me know if you have any questions or any things you want me to change.
Results: