I have a table in which data gets appended for the changes. No delete or update, only append is done by a cloud run job.
Base table
Supplier_ID | Supplier_Name | Supplier_Contact | Last_Modified |
---|---|---|---|
123 | ABC | 03 483 394 | 2023-05-01 12:34:56 |
124 | ABD | 02 848 939 | 2023-05-01 12:34:56 |
123 | ABC | 03 483 345 | 2023-05-02 10:45:05 |
124 | ABD | 02 848 837 | 2023-05-02 10:45:05 |
123 | ABC | 03 478 102 | 2023-05-08 11:09:15 |
I'd like to create another table like below.
Supplier_ID | Supplier_Name | Supplier_Contact | Effective_From | Effective_To | is_active |
---|---|---|---|---|---|
123 | ABC | 03 483 394 | 2023-05-01 12:34:56 | 2023-05-02 10:45:05 | N |
123 | ABC | 03 483 345 | 2023-05-02 10:45:05 | 2023-05-08 11:09:15 | N |
123 | ABC | 03 478 102 | 2023-05-08 11:09:15 | 9999-12-21 00:00:00 | Y |
124 | ABD | 02 848 939 | 2023-05-01 12:34:56 | 2023-05-02 10:45:05 | N |
124 | ABD | 02 848 837 | 2023-05-02 10:45:05 | 9999-12-21 00:00:00 | Y |
What would be the best way to achieve? I was trying to find a way to do this using dbt but unable to find any way.
You can use this below query for reference and create your model in dbt