How many login-to-view pairs will a join create for each user?

An analyst wants to find out how many times users moved from login to view. They've joined the events table to itself and counted the resulting pairs for each user. What table will the query return?

Predict the resultJOIN and row countsMiddleAnalystData EngineerBackend
Input data · iv_events
iduser_idevent_typecreated_at
11login2026-01-31 23:59:00
21login2026-01-31 23:59:00
31view2026-02-01 00:00:00
42login2026-02-01 08:00:00
52view2026-02-01 08:05:00
62view2026-02-01 08:05:00
73login2026-02-02 10:00:00
8NULLview2026-02-03 11:00:00
91purchase2026-02-03 12:00:00
102logout2026-02-28 23:59:59

Query

SELECT a.user_id,
       COUNT(*) AS event_pairs
FROM iv_events a
JOIN iv_events b ON b.user_id = a.user_id
WHERE a.event_type = 'login'
  AND b.event_type = 'view'
  AND a.created_at <= b.created_at
GROUP BY a.user_id
ORDER BY a.user_id