I have the following table:
| id | date | type |
|---|---|---|
| 001 | 2022-01-01 | A |
| 001 | 2022-01-03 | B |
| 001 | 2022-01-02 | B |
| 001 | 2022-02-02 | A |
| 002 | 2022-01-01 | A |
| 002 | 2022-01-03 | B |
| 004 | 2022-01-01 | A |
| 004 | 2022-01-03 | B |
And I need to sort the dates decending, group by ID and Type and get the time between the dates by ID and Type, either in seconds or months days
| id | date | type | time diff |
|---|---|---|---|
| 001 | 2022-01-01 | A | 0 |
| 001 | 2022-01-02 | B | 1 |
| 001 | 2022-01-03 | B | 1 |
| 001 | 2022-02-02 | A | 31 |
| 002 | 2022-01-01 | A | 0 |
| 002 | 2022-01-03 | B | 2 |
| 004 | 2022-01-01 | A | 0 |
| 004 | 2022-01-03 | B | 2 |