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 Join and Grouping Query
00:00
5 left

SQL Join and Grouping Query

MediumSQL · PostgreSQL

Problem

Xero's product discovery team is testing a catalog reporting pattern for grouped product data. Using the game catalog below, write a PostgreSQL query that counts short games for every console.

Use a threshold of 10 hours, and treat a game as short only when playtime_hours < 10. Consoles with no qualifying games must still appear with a count of zero.

Requirements

  1. Join consoles to their game mappings and game details.
  2. Count each qualifying game at most once per console, even if duplicate mappings exist.
  3. Include consoles with no matching or qualifying games, and order the output alphabetically by console name.

Schema

consoles
ColumnTypeDescription
console_idPKINTEGERUnique console identifier
console_nameVARCHAR(100)Display name of the console
games
ColumnTypeDescription
game_idPKINTEGERUnique game identifier
game_titleVARCHAR(150)Game title
playtime_hoursNUMERIC(6,2)Estimated hours needed to complete the game
console_games
ColumnTypeDescription
game_idINTEGERReference to games.game_id
console_idINTEGERReference to consoles.console_id
Tablesconsolesgamesconsole_games
Interviewer

Your question is SQL Join and Grouping Query. 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.