Hi I am working in an Azure Databricks and I am looking for a SQL query solution.
Assuming that my db has five columns:
| ID | EVENT_DATE | JOB_TITLE | PAY |
|---|---|---|---|
| 12345 | 2021-01-01 | VP1 | 100,000 |
| 12345 | 2020-01-10 | VP1 | 90,000 |
| 12345 | 2019-01-20 | Analyst1 | 80,000 |
| 12346 | 2021-02-01 | VP2 | 200,000 |
| 12346 | 2020-02-10 | Analyst2 | 150,000 |
| 12346 | 2020-01-20 | Analyst2 | 110,000 |
Basically I want the EVENT_DATE when JOB_TITLE changed the last time. This is my desired output:
| ID | JOB_TITLE | PAY | LAST_JOB_CHANGE_DATE |
|---|---|---|---|
| 12345 | VP1 | 90,000 | 2021-01-10 |
| 12346 | VP2 | 200,000 | 2021-02-01 |
For the last column LAST_JOB_CHANGE_DATE, we are pulling from the 2nd and 4th row of the table because that's the date when they changed job the last time.
Thank you!
