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
SQL for a Given Scenario
00:00
5 left

SQL for a Given Scenario

MediumSQL · PostgreSQL

Problem

What would the SQL look like for a scenario presented by the interviewer?

Use the provided companies, payroll_runs, and payroll_items tables. Return company-level totals for completed payroll runs during the first quarter of 2025, including companies with no qualifying activity.

Output

  1. One row per company with company_id, company_name, paid_workers, and total_gross_pay
  2. Include every company, using zero for companies without qualifying payroll items
  3. Sort by total_gross_pay descending, then company_id ascending

Schema

companies
ColumnTypeDescription
company_idPKINTUnique company identifier
company_nameVARCHAR(120)Company display name
payroll_runs
ColumnTypeDescription
payroll_run_idPKINTUnique payroll run identifier
company_idINTCompany associated with the payroll run
payroll_dateDATEPayroll processing date
statusVARCHAR(20)Payroll run status
payroll_items
ColumnTypeDescription
payroll_item_idPKINTUnique payroll item identifier
payroll_run_idINTPayroll run containing the item
employee_idINTEmployee associated with the item
gross_payNUMERIC(12,2)Gross pay amount for the employee
Tablescompaniespayroll_runspayroll_items
Interviewer

Your question is SQL for a Given Scenario. 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.