How would you perform a self-join to compare user activity across different time periods?
Use the user_activity table to compare each user's activity in one month against the previous month. Return only users who were active in both periods.
user_id, current_month, current_activity, previous_month_activity, activity_changeuser_id, then current_month| Column | Type | Description |
|---|---|---|
| activity_idPK | INT | Unique row identifier |
| user_id | INT | User identifier |
| activity_month | DATE | Month bucket for activity, stored as the first day of the month |
| activity_count | INT | Number of active days or actions in the month |