Given a schema of user activity logs, write a query using window functions to find the most active session for each user on Squarespace.
Use the provided users, sessions, and activity_logs tables. Count activity events per session and return only users with at least one logged activity. Break ties by the most recently started session, then by the lowest session ID.
Output
- One row per user with logged activity, ordered by
user_id.
- Columns:
user_id, display_name, session_id, activity_count, and started_at.
activity_count is the number of activity log rows in the selected session.