cswork / libraryOpen practice workspace

Coding questions · Mixpanel

Count Users Active After Signup

Count distinct users with at least one event on or after signup using a PostgreSQL query.

Count Users with an Event On or After Signup

You have these tables:

TableColumnMeaning
usersuser_idUser identifier.
userssignup_dateThe user's signup date or timestamp.
usersplan_typeThe user's plan type.
eventsuser_idUser associated with an event.
eventsevent_tsEvent timestamp.

Write one read-only PostgreSQL query to count distinct users who have at least one event whose event_ts is greater than or equal to their signup_date. Match events to user records by user_id.

A user with multiple qualifying events is counted once. Users with no qualifying events are excluded from the count.

Return exactly one row with one column named users_with_event. If nobody qualifies, the count is zero. Output row order is unrestricted.

Count Users with an Event On or After Signup

Table users

columntypeconstraints
user_idINTEGER
signup_dateTIMESTAMP
plan_typeTEXT

Sample data:

plan_typesignup_dateuser_id
free2026-09-01 12:00:001
pro2026-09-01 15:00:002
enterprise2026-09-01 08:00:003
freeNULL4
pro2026-09-01 10:00:005
trial2026-09-01 10:00:006
free2026-09-01 13:00:007
NULL2026-09-01 23:00:008

Table events

columntypeconstraints
user_idINTEGER
event_tsTIMESTAMP

Sample data:

event_tsuser_id
2026-09-01 12:00:001
2026-09-02 12:00:001
2026-09-02 12:00:001
2026-09-01 14:59:592
2027-01-01 00:00:003
2026-09-02 10:00:004
NULL6
2026-09-01 12:59:597
2026-09-01 14:00:007
2026-09-01 23:00:008
2026-09-01 12:00:0099
2026-09-01 12:00:00NULL

Expected output

users_with_event
4