Suppose I have the following table:
start_data | end_date
----------------------
t1 | Null
Null | t2
t3 | Null
Null | t4
t5 | Null
The output should be like this:
start_data | end_date
----------------------
t1 | t2
t3 | t4
t5 | Null
notes:
- the type of ti is date
- ti < ti+1 holds true for all values.
pseudo code:
for every record i
xi <— start_date
yi <— end_date
zi <—- min(yi) && xi>yi
(xi,zi) should be the output for this record i
Is it solvable using native SQL?
Best Answer
This query is a model. The final text is dependent by DBMS.
Maybe you will need to replace MIN/MAX with
CASE WHEN rn%2 = [0|1]