let's say I have the table below:
| id | user_id | level | date_created |
|---|---|---|---|
| 1 | 1 | 2 | 2019-07-01T18:53:41.000Z |
| 2 | 1 | 3 | 2020-07-01T18:53:41.000Z |
| 3 | 1 | 4 | 2021-07-01T18:53:41.000Z |
| 4 | 2 | 2 | 2020-07-01T18:53:41.000Z |
Let's say I want to get a user's level for each of the last 3 years, based on date created, in a single row.
Something like:
SELECT user_id, (some query here) AS "level_2019"
, (some query here) AS "level_2020", (some query here) AS "level_2021"
FROM table
Is this something that's possible for a single select statement? I'd also like the level for that year to be null if they don't have one for that year.
Thank you!