Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Interaction Sequences in SQL
00:00
5 left

Top Interaction Sequences in SQL

MediumSQL · PostgreSQL

Problem

Given a table of patient touchpoints, how would you write a query to identify the top three most frequent interaction sequences leading to a treatment decision?

Treat a sequence as the non-null touchpoint types for one decision, ordered by touchpoint order. Include only touchpoints occurring on or before the decision date.

Output

  1. Return one row per selected sequence with sequence_rank, interaction_sequence, and decision_count.
  2. Include the three most frequent distinct sequences, ordered by count descending and sequence text ascending to break ties.

Schema

patient_touchpoints
ColumnTypeDescription
touchpoint_idPKINTUnique touchpoint identifier
patient_idINTPatient associated with the touchpoint
decision_idINTTreatment decision associated with the touchpoint
touchpoint_typeVARCHAR(100)Type of patient interaction
occurred_atDATEDate the interaction occurred
touchpoint_orderINTOrder of the interaction within the decision journey
treatment_decisions
ColumnTypeDescription
decision_idPKINTUnique treatment decision identifier
patient_idINTPatient receiving the decision
decision_dateDATEDate of the treatment decision
treatment_nameVARCHAR(100)Treatment selected at the decision
Tablespatient_touchpointstreatment_decisions
Interviewer

Your question is Top Interaction Sequences in SQL. Start with the requirements and the two tables in the Question tab.

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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.