Reputation: 17
I have a column of date in an Oracle table
date_column
-----------
12/02/2016
05/02/2016
25/01/2016
08/01/2016
18/12/2015
...
I would like to know if there is a method to calculate in an other column the number of days every couple of successive dates. For example the number of days between 12/02/2016
and 05/02/2016
, the number of days between 05/02/2016
and 25/01/2016
and so on.
Upvotes: 0
Views: 54
Reputation:
This can be done using window functions:
select date_column,
lag(date_column) over (order by date_column) - date_column as days
from the_table
order by date_column;
lag()
returns the value of the column from the previous row based on the sort order defined in the order by
part.
In Oracle date - date
returns the number of days
Upvotes: 3