I have the following data represented in a table like this:
User | Type | Date |
---|---|---|
A | Mobile | 2019-01-10 |
A | Mobile | 2019-01-20 |
A | Desktop | 2019-03-01 |
A | Desktop | 2019-03-20 |
A | 2021-01-01 | |
A | 2020-01-02 | |
A | Desktop | 2021-01-03 |
A | Desktop | 2021-01-04 |
A | Desktop | 2021-01-05 |
Using PostgreSQL - I want to achieve the following:
User | First_Type | First Type Initial Date | Last_Type | Last_Type_Initial_Date |
---|---|---|---|---|
A | Mobile | 2019-01-10 | Desktop | 2021-01-03 |
So for each user, I want to capture the initial date and type but then also, on the same row (but diff columns), have their last type they "switched" to but with the first date the switch occurred and not the last record of activity on that type.