Hello!
I have a table with the following structure:
id | fecha_inicio
---+--------------------
10 | 2016-12-01 10:15:00
10 | 2016-12-03 16:02:00
11 | 2016-12-02 11:23:00
I want to build a query that has the start and the end of the period, where, for example, the end date of the first period of the id 10
is 2016-12-03 16:02:00
. The result I'm looking for is something like the following:
id | fecha_inicio | fecha_final
---+---------------------+--------------------
10 | 2016-12-01 10:15:00 | 2016-12-03 16:02:00
10 | 2016-12-03 16:02:00 | NULL
11 | 2016-12-02 11:23:00 | NULL
Is there a way to build this query using only SQL expressions? I know that it is possible to build it using other languages, but it would be much easier for me to do it directly in the database.
Cheers