Write a SQL query to extract specific user engagement metrics across multiple joined tables.
Use the provided user, session, and engagement event data. Return metrics for users whose marketing_opt_in is true, including users with no sessions or events.
Output
- One row per opted-in user with
user_id, email, total_sessions, engaged_sessions, engagement_event_count, and last_engaged_at.
- Count each session once, count sessions containing at least one event as engaged, and exclude events not associated with a returned user's session.
- Order by
user_id ascending.