Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Join and Grouping Query

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

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

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results