I have a table data structure like below,
| ID | NAME | START_DATE | END_DATE | CREATE_DATE |
|---|---|---|---|---|
| 100 | Apple | 01-NOV-23 | 31-DEC-99 | 01-NOV-23 |
| 100 | Anar | 10-OCT-23 | 31-DEC-99 | 12-SEP-23 |
| 100 | Anar | 04-SEP-23 | 10-OCT-23 | 04-SEP-23 |
| 101 | Ant | 01-OCT-23 | 31-DEC-99 | 01-OCT-23 |
| 101 | Bee | 10-APR-23 | 31-DEC-99 | 12-APR-23 |
| 101 | Bee | 04-MAR-23 | 10-APR-23 | 04-MAR-23 |
I want to update data like below, (2nd row start_date should update like CREATE_DATE and END_DATE should update from next start_date)
| ID | NAME | START_DATE | END_DATE | CREATE_DATE |
|---|---|---|---|---|
| 100 | Apple | 01-NOV-2023 | 31-DEC-99 | 01-NOV-2023 |
| **100 | Anar | 12-SEP-2023 | 01-NOV-2023 | 12-SEP-2023** |
| 100 | Anar | 04-SEP-2023 | 10-OCT-23 | 04-SEP-2023 |
| 101 | Ant | 01-OCT-2023 | 31-DEC-99 | 01-OCT-2023 |
| **101 | Bee | 12-APR-2023 | 01-OCT-2023 | 12-APR-2023** |
| 101 | Bee | 04-MAR-2023 | 10-APR-23 | 10-APR-23 |
Note- The thing her is for one id one user should have end_date as 31-DEC-99
I'm assuming that you:
end_dateis9999-12-31;create_dateas thestart_date; andcreate_dateas theend_dateif it exists else use the currentend_date.Given that assumption then you can use
CASEexpressions and theLEADanalytic function:Which, for the sample data:
Outputs:
fiddle