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
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess 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
Get started
Database Design With SQL
00:00
5 left

Database Design With SQL

MediumSQL · PostgreSQL

Problem

Describe how you would design a database and write the SQL queries needed to support the use cases described in the prompt.

Use the provided patient, encounter, and diagnosis entities. The report must include patients without completed encounters and count diagnoses associated only with each patient's latest completed encounter.

Output

  1. One row per patient with patient_id, patient_name, latest_completed_encounter, diagnosis_count, and encounter_status.
  2. Include all patients, use No completed encounter when applicable, and sort by patient_id ascending.

Schema

patients
ColumnTypeDescription
patient_idPKINTUnique patient identifier
patient_nameVARCHAR(100)Patient display name
encounters
ColumnTypeDescription
encounter_idPKINTUnique encounter identifier
patient_idINTPatient associated with the encounter
encounter_dateDATEDate of the encounter
statusVARCHAR(20)Encounter status
diagnoses
ColumnTypeDescription
diagnosis_idPKINTUnique diagnosis identifier
encounter_idINTEncounter associated with the diagnosis
diagnosis_codeVARCHAR(20)Diagnosis classification code
Tablespatientsencountersdiagnoses
Interviewer

Your question is Database Design With SQL. Start with the requirements and the three 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.