Difference between two rows of a table.
TauceefMay 14 2013 — edited May 15 2013Hi All,
I have a requirement where I need to calculate the difference of a column, but the values are in two rows.
Its exactly like this, I am having a table where in I have stored incidents with their status and their modified dates
example:
Incident_Id : Status : Modified_Date(in seconds from a specific date)
1 : 1 : 9080890
1 : 2 : 9080999
1 : 3 : 9081900
2 : 1 : 10000900
2 : 2 : 10001000
2 : 3 : 10002000
Now the requirement is I have to show the time spent by each incident in each status.
ie for status 1 I need the difference between modified date of status 2 and modified date of status 1 likewise
for status 2 need the difference between modified date of status 3 and modified date of status 2 and so on.
the actual result I need is like this
Incident_Id : Status : Timespent
1: 1: (modified_date(status2) - modified_date(status1))
Please help me to write the query for this.
Regards,
Tauceef