I searched for the above topic and only getting query in Oracle which uses certain keywords specific to oracle.
+----------+------------+--------------------+
| Agent_id | valid_from | last_modified_date |
+----------+------------+--------------------+
| 13002 | 2010-12-25 | 2011-01-03 |
| 13002 | 2011-01-03 | 2011-08-25 |
| 13002 | 2011-08-26 | 2012-12-30 |
| 13002 | 2013-01-01 | 2013-01-01 |
| 12110 | 2014-02-27 | 2014-03-03 |
| 12110 | 2014-03-25 | 2014-12-25 |
+----------+------------+--------------------+
I have the above table values and want to retrieve difference between last_modified_date
of 1st row and valid_from
date of 2nd row and likewise for the same agent(agent id
here).
Result table:
+----------+------------+--------------------+-----------+
| Agent_id | valid_from | last_modified_date | datediff |
+----------+------------+--------------------+-----------+
| 13002 | 2010-12-25 | 2011-01-03 | 0 |
| 13002 | 2011-01-03 | 2011-08-25 | 0 |
| 13002 | 2011-08-26 | 2012-12-30 | 1 |
| 13002 | 2013-01-01 | 2013-01-01 | 1 |
| 12110 | 2014-02-27 | 2014-03-03 | 0 |
| 12110 | 2014-03-25 | 2014-12-25 | 22 |
+----------+------------+--------------------+-----------+
If there is no date for comparison on first row diff should be 0
.
These are set of dates where the status gets changed from Y to D and to find when the agent is without any activity.
please help!!