I have a dimension table that is a type 2 scd like this:
| Empl | job_id | old_job_id |
|---|---|---|
| 12345 | 101 | 98 |
| 12345 | 120 | 101 |
| 12345 | 130 | 120 |
I need to know the current job_id like this:
| Empl | job_id | current_job_id |
|---|---|---|
| 12345 | 101 | 130 |
| 12345 | 120 | 130 |
| 12345 | 130 | 130 |
can this be done with a sql query in a view?
I have tried a self join but that doesn't give me the current view for all records and there is not easy way I can think of to identify how many old jobs an employee has.
Also, I found another related issue. |job_id | old_job_id | job_desc| |-----|--------|---------------| |100| NULL| CEO| |110| NULL| Regional Mgr| |120| 110| Regional Manager| |130| NULL| Salesperson|
I'm looking to have this |job_id | Current_job_id| Current_job_desc| |-----|--------|---------------| |100| 100| CEO| |110| 120| Regional Manager| |120| 120| Regional Manager| |130| 130| Salesperson|
thanks for the assistance.
Something like :
Please respect the post chart by giving table's DDL and some INSERT to reproduce your trouble...