Premium problem98. Ordered Funnel Completion

Hard Locked

events(user_id, event_type, event_at)

Measure the funnel view_product then add_to_cart then purchase across September 2026. The steps must happen in that order, each after the one before it, though unrelated events in between are fine. A user counts once.

The denominator is the users who entered the funnel, meaning anyone with a view_product in the month, measured from their first such view.

Return funnel_users, completed_users and completion_pct rounded to two decimals.

Counting users who have all three event types anywhere in the month overstates completion, because a purchase that happened before the cart is not a completion.

Tables

events

user_id  event_type    event_at
-------  ------------  -------------------
10       view_product  2026-09-01 10:00:00
10       add_to_cart   2026-09-01 11:00:00
10       purchase      2026-09-01 12:00:00
11       view_product  2026-09-02 10:00:00
11       purchase      2026-09-02 11:00:00
11       add_to_cart   2026-09-02 12:00:00
12       view_product  2026-09-03 10:00:00
12       search        2026-09-03 10:30:00
... 5 more row(s)

Expected result

funnel_users  completed_users  completion_pct
------------  ---------------  --------------
4             2                50.00

Premium problem

This one's part of Premium. Unlock the full MySQL track plus every other premium problem on the site.

Write one SELECT query