F
F
Faith2017-10-19 09:14:03
Database
Faith, 2017-10-19 09:14:03

How to sequentially subtract dates from one another, located in the same column?

How to first subtract the second from the first date, and then the third from the second, etc. so that you can display the difference in the number of months and compare? I know that there is a special function for dates, but how exactly to count sequentially? For clarity, an example table:
59e8425253195897024877.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Y, 2017-10-19
@x_shader

MSSQL is not at hand, but something like this:
https://docs.microsoft.com/en-us/sql/t-sql/functio...
https://docs.microsoft.com/en-us/sql /t-sql/functio...
Add column (in SELECT):
DATEDIFF(month, dates, lag(dates) over (order by dates))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question