SQL Active Users

Active users are distinct users who perform an explicitly approved qualifying event.

What & Why

An active user is a distinct user_id with at least one event from the agreed activity list during the reporting window.

This lesson groups the approved session_started, feature_used, and report_viewed events first so the activity contract is visible before daily or monthly windows are added.

See How It Works

BUSINESS QUESTION

Growth wants distinct users by qualifying event so the team can review which behaviors belong in the active-user definition.

iduser_idevent_namecreated_atproperties
1001101signup2024-01-15 09:12:00+00{"source":"organic"}
1002101activated2024-01-16 14:25:00+00{"step":"workspace"}
1003102signup2024-02-10 11:08:00+00{"source":"paid"}
1004103report_viewed2024-03-12 16:40:00+00{"report":"retention"}
EXAMPLE QUERY
SELECT
  event_name,
  COUNT(DISTINCT user_id) AS active_users
FROM growth.events
WHERE user_id IS NOT NULL
  AND event_name IN ('session_started', 'feature_used', 'report_viewed')
GROUP BY event_name
ORDER BY active_users DESC, event_name;
RESULT — qualifying active events
event_nameactive_users
report_viewed1

Only report_viewed appears in both the representative event rows and the lesson's qualifying event list.

This lesson's practice is part of Pro.

Advanced business practice

Sign up free to try it on a real business scenario