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
SQL with Joins for Metrics
00:00
5 left

SQL with Joins for Metrics

MediumSQL · PostgreSQL

Problem

Given a small DB schema, write SQL queries (joins) to answer several questions. Asked in the LLD stage.

Output

  1. Return one row per active show.
  2. Include show_name, host_name, episode_count, published_episode_count, and total_listens.
  3. episode_count should count all episodes linked to the show, published_episode_count should count only published episodes, and total_listens should sum listens across all episodes for that show.
  4. Exclude shows with no host match.
  5. Sort by total_listens descending, then show_name ascending.

Schema

hosts
ColumnTypeDescription
host_idPKINTUnique host identifier
host_nameVARCHAR(100)Host display name
regionVARCHAR(50)Host region
shows
ColumnTypeDescription
show_idPKINTUnique show identifier
show_nameVARCHAR(120)Show title
host_idINTHost linked to the show
is_activeBOOLEANWhether the show is active
episodes
ColumnTypeDescription
episode_idPKINTUnique episode identifier
show_idINTShow linked to the episode
episode_titleVARCHAR(150)Episode title
statusVARCHAR(20)Episode publication status
listen_countINTNumber of listens recorded for the episode
Tablesshowshostsepisodes
Interviewer

Your question is SQL with Joins for Metrics. 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.