I have this table without pk
| Peo | Pos | DATE_BEGIN | DATE_END | XXXX |
+------+-----+------------+------------+------+
| 9302 | 8 | 2017-10-02 | 2017-12-31 | NULL |
| 9302 | 8 | 2018-01-01 | 2018-01-01 | NULL |
| 9302 | 8 | 2018-01-02 | 2018-05-31 | NULL |
| 9302 | 8 | 2018-06-01 | 9999-12-31 | NULL |
And I want to get the time pass in Pos 8 from the older DATE_BEGIN
to the newer Date_END
that could be 9999-12-31 when undefined in which case would be the actual date. For this table would be 2017-10-02 to 9999-12-31 (2020/06/23, actual date).
One problem is that for the table below it should only get the last row as is the total time that the person is in the Pos because it was changed. so will be (2018-06-01) - (9999-12-31 - actual date)
| Peo | Pos | DATE_BEGIN | DATE_END | XXXX |
+------+-----+------------+------------+------+
| 9302 | 8 | 2017-10-02 | 2017-12-31 | NULL |
| 9302 | 8 | 2018-01-01 | 2018-01-01 | NULL |
| 9302 | 7 | 2018-01-02 | 2018-05-31 | NULL |
| 9302 | 8 | 2018-06-01 | 9999-12-31 | NULL |