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 5 Best-Selling Models Query
00:00
5 left

Top 5 Best-Selling Models Query

MediumSQL · PostgreSQL

Problem

Write a query to find the top 5 best-selling car models from a given sales table.

Count only rows where sale_status is completed, and exclude records without a car model. Break ties alphabetically by model_name.

Output

  1. One row per selected car model
  2. Columns: model_name and sales_count
  3. Return at most five rows, ordered by sales_count descending, then model_name ascending

Schema

sales
ColumnTypeDescription
sale_idPKINTUnique identifier for the sale
model_nameVARCHAR(100)Car model sold
sale_statusVARCHAR(30)Current status of the sale
sold_atDATEDate associated with the sale
Tablessales
Interviewer

Your question is Top 5 Best-Selling Models Query. Start with the requirements and the one table 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.