I have 3 month tables for January, February and March.
January table:
ID | Date |
---|---|
1 | 01/01/2022 |
2 | 01/02/2022 |
3 | 01/02/2022 |
1 | 01/10/2022 |
4 | 01/12/2022 |
February table:
ID | Date |
---|---|
1 | 02/01/2022 |
2 | 02/07/2022 |
3 | 02/10/2022 |
2 | 02/15/2022 |
5 | 02/17/2022 |
March table:
ID | Date |
---|---|
1 | 03/19/2022 |
2 | 03/11/2022 |
3 | 03/14/2022 |
3 | 03/25/2022 |
6 | 03/13/2022 |
Lets assume i make a UNION ALL between all three tables. Now taking March as reference point, i need to classify each ID according to the last date it appeared in the table (the same ID can be repeated in the table with the same or different date, the max date is to be used for the excercise). Now i need to check in which months the IDs appear and be able to sort them according to the month where the ID is present.
Months | ID | Last Date |
---|---|---|
Jan-Feb-Mar | 1 | 03/19/12 |
Jan-Feb-Mar | 2 | 03/11/12 |
Jan-Feb-Mar | 3 | 03/14/12 |
Jan | 4 | 01/12/2022 |
Feb | 5 | 02/17/2022 |
Mar | 6 | 03/13/2022 |
Also i would need to classify according to a range of days since the last date an ID appeared. The range of days are the following: 1-30, 31-60 and 61-90. It should look something like this table below, even better if the field Months from the previous example shown is added too
Range of Days | ID | Last Date | Months |
---|---|---|---|
1-30 | 1 | 03/19/12 | Jan-Feb-Mar |
1-30 | 2 | 03/11/12 | Jan-Feb-Mar |
1-30 | 3 | 03/14/12 | Jan-Feb-Mar |
61-90 | 4 | 01/12/2022 | Jan |
31-60 | 5 | 02/17/2022 | Feb |
1-30 | 6 | 03/13/2022 | Mar |