Write SQL and Python, run instantly in your browser, and track your progress.
You are a Product Analyst at Reddit. The Engagement team wants to analyze posting frequency by comparing each post's date to the user's previous post date. Use shift within each user group to get the previous post's created_at date.
| Column Name | Type |
|---|---|
| post_id | int64 |
| user_id | int64 |
| content_type | object |
| created_at | object |
You are a Product Analyst at Reddit. The Engagement team wants to analyze posting frequency by comparing each post's date to the user's previous post date. Use shift within each user group to get the previous post's created_at date.
| Column Name | Type |
|---|---|
| post_id | int64 |
| user_id | int64 |
| content_type | object |
| created_at | object |
| post_id | user_id | content_type | created_at |
|---|---|---|---|
| 1 | 101 | text | 2025-01-10 |
| 2 | 102 | image | 2025-01-11 |
| 3 | 101 | image |
| post_id | user_id | content_type | created_at |
|---|---|---|---|
| 1 | 101 | text | 2025-01-10 |
| 2 | 102 | image | 2025-01-11 |
| 3 | 101 | image |
| post_id | user_id | created_at | prev_post_date |
|---|---|---|---|
| 2 | 1 | 2025-04-20 | NaN |
| 1 | 1 | 2025-05-28 | 2025-04-20 |
| 3 | 1 | 2025-06-02 | 2025-05-28 |
| 6 | 2 | 2025-03-28 | NaN |
| post_id | user_id | created_at | prev_post_date |
|---|---|---|---|
| 2 | 1 | 2025-04-20 | NaN |
| 1 | 1 | 2025-05-28 | 2025-04-20 |
| 3 | 1 | 2025-06-02 | 2025-05-28 |
| 6 | 2 | 2025-03-28 | NaN |
Showing first 5 of 230 rows.
Showing first 5 of 230 rows.
1. Data Selection:
2. Window Function:
3. Output:
1. Data Selection:
2. Window Function:
3. Output:
| 2025-01-12 |
| 2025-01-12 |
| 4 | 102 | text | 2025-01-13 |
| 4 | 102 | text | 2025-01-13 |
| 5 | 101 | text | 2025-01-15 |
| 5 | 101 | text | 2025-01-15 |
| 4 | 2 | 2025-07-19 | 2025-03-28 |
| 4 | 2 | 2025-07-19 | 2025-03-28 |