Back to problems

Estimate Page-Visit Duration from the Next User Event

SQL · Airbnb · Medium

Given a page_events table, compute an estimated page-visit duration for each recorded event. A visit starts at one event and ends when the same user has their next event in chronological order. The input table has these columns: event_id INTEGER: unique event identifier, primary key. user_id INTEGER: non-null user identifier. page_id TEXT: non-null page identifier. event_time TIMESTAMP: non-null timestamp with whole-second precision. Write one read-only PostgreSQL query that…

Checking your access…