Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Most Common User Navigation Paths

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

Your question is Most Common User Navigation Paths. Start with the requirements and the three 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

NovaFlow wants to understand how users move through its product. Write a PostgreSQL query to identify the most common 3-step navigation paths users take within a session.

Use the event stream to build ordered page paths from consecutive events. Only include sessions tied to active users, and ignore events where page_name is NULL.

Requirements

  1. Build 3-step paths using each user's ordered events within the same session.
  2. Use event timestamp order, and break ties with event_id.
  3. Only include sessions from users where users.is_active = TRUE.
  4. Exclude incomplete paths where step 2 or step 3 is missing.
  5. Return each unique path, the number of distinct sessions that followed it, and its rank by popularity.
  6. Sort by path rank, then path name.

Schema

users
ColumnTypeDescription
user_idPKINTPrimary key for the user
user_nameVARCHAR(100)User's full name
signup_dateDATEDate the user signed up
is_activeBOOLEANWhether the user is currently active
sessions
ColumnTypeDescription
session_idPKINTPrimary key for the session
user_idINTUser who owns the session
session_startTIMESTAMPTimestamp when the session started
device_typeVARCHAR(50)Device type used in the session
events
ColumnTypeDescription
event_idPKINTPrimary key for the event
session_idINTSession where the event occurred
event_timeTIMESTAMPTimestamp of the event
page_nameVARCHAR(100)Page or screen viewed by the user
event_typeVARCHAR(50)Type of event recorded
Tablesuserssessionsevents
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results