Twitter wants to monitor user engagement by looking at their tweet frequency. Specifically, you need to calculate the 3-day rolling average of tweets for each user.
Write an SQL query to calculate the 3-day rolling average of tweets for each user_id and tweet_date.
| user_id(INTEGER) | tweet_date(DATE) | tweet_count(INTEGER) |
|---|---|---|
| 1 | 2022-06-01 | 2 |
| 1 | 2022-06-02 | 1 |
| 1 | 2022-06-03 | 3 |
| 1 | 2022-06-04 | 4 |
| 1 | 2022-06-05 | 5 |
| 2 | 2022-06-01 | 10 |
| 2 | 2022-06-02 | 5 |
| 2 | 2022-06-03 | 0 |
| 2 | 2022-06-04 | 10 |
| 2 | 2022-06-05 | 2 |
| 3 | 2022-06-01 | 1 |
| 3 | 2022-06-02 | 1 |
| 3 | 2022-06-03 | 7 |
| 4 | 2022-06-01 | 2 |
| 4 | 2022-06-02 | 4 |
| user_id(INTEGER) | tweet_date(DATE) | rolling_avg(DECIMAL) |
|---|---|---|
| 1 | 2022-06-01 | 2 |
| 1 | 2022-06-02 | 1.5 |
| 1 | 2022-06-03 | 2 |
| 1 | 2022-06-04 | 2.67 |
| 1 | 2022-06-05 | 4 |
| 2 | 2022-06-01 | 10 |
| 2 | 2022-06-02 | 7.5 |
| 2 | 2022-06-03 | 5 |
| 2 | 2022-06-04 | 5 |
| 2 | 2022-06-05 | 4 |
| 3 | 2022-06-01 | 1 |
| 3 | 2022-06-02 | 1 |
| 3 | 2022-06-03 | 3 |
| 4 | 2022-06-01 | 2 |
| 4 | 2022-06-02 | 3 |