Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Top Three Event Sequences

HardSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is Top Three Event Sequences. Start with the requirements and the two tables on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Munich Re wants to understand common navigation patterns in its Risk Intelligence portal. Each interaction belongs to a session and has an event timestamp. Write a PostgreSQL query that identifies the three most frequent complete event sequences across sessions.

Requirements

  1. Join sessions to their interactions and order events within each session by event_at, using interaction_id as a deterministic tie-breaker.
  2. Represent each session sequence as event names joined with >, excluding interactions whose event name is NULL.
  3. Count how many sessions produced each sequence and return the top three, sorted by frequency descending and sequence ascending to make ties deterministic.

Schema

sessions
ColumnTypeDescription
session_idPKINTUnique portal session identifier
user_idINTMunich Re portal user identifier
started_atTIMESTAMPSession start timestamp
interactions
ColumnTypeDescription
interaction_idPKINTUnique interaction identifier
session_idINTAssociated session identifier
event_nameVARCHAR(50)Risk Intelligence portal event name
event_atTIMESTAMPEvent occurrence timestamp
Tablessessionsinteractions
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results