The goal is to understand which manager provides the client's order without grouping by the managers. It's important, that during the time, clients' managers are changing, and that may happen several times, including returnee to the previous manager.
We have an Orders
table:
Client | Order Date | Order Amount |
---|---|---|
Cl.1 | 01/01/22 | 120 |
Cl.2 | 01/01/22 | 450 |
Cl.3 | 02/01/22 | 340 |
Cl.4 | 10/01/22 | 210 |
Cl.1 | 05/02/22 | 119 |
Cl.2 | 07/02/22 | 454 |
Cl.3 | 08/02/22 | 342 |
Cl.4 | 11/02/22 | 225 |
We have a Managers
changing table:
Client | Manager Change Date | Manager |
---|---|---|
Cl.3 | 01/01/22 | Mng.2 |
Cl.4 | 08/01/22 | Mng.3 |
Cl.2 | 07/02/22 | Mng.2 |
Cl.3 | 06/02/22 | Mng.1 |
Cl.1 | 15/02/22 | Mng.2 |
The default manager at the start is Mng.1.
The result table is Orders
table + Manager column:
Client | Order Date | Order Amount | Manager |
---|---|---|---|
Cl.1 | 01/01/22 | 120 | Mng.1 |
Cl.2 | 01/01/22 | 450 | Mng.1 |
Cl.3 | 02/01/22 | 340 | Mng.2 |
Cl.4 | 10/01/22 | 210 | Mng.3 |
Cl.1 | 05/02/22 | 119 | Mng.1 |
Cl.2 | 07/02/22 | 454 | Mng.2 |
Cl.3 | 08/02/22 | 342 | Mng.1 |
Cl.4 | 11/02/22 | 225 | Mng.3 |