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 Three Payroll Runs
00:00
5 left

Top Three Payroll Runs

MediumSQL · PostgreSQL

Problem

Write a query to identify the top three highest-paying payroll runs for each business category in a given month at Gusto.

Use May 2024 for the sample data and include completed payroll runs only. Exclude runs whose business has no category.

Output

  1. One row per qualifying payroll run with business_category, payroll_run_id, business_id, payroll_date, total_gross_pay, and payroll_rank.
  2. Include at most three runs per category, with ties broken by the lower payroll_run_id.
  3. Order by business_category, then payroll_rank.

Schema

businesses
ColumnTypeDescription
business_idPKINTUnique identifier for a business
business_nameVARCHAR(150)Business name
business_categoryVARCHAR(80)Business category used to partition payroll runs
payroll_runs
ColumnTypeDescription
payroll_run_idPKINTUnique identifier for a payroll run
business_idINTBusiness associated with the payroll run
payroll_dateDATEDate of the payroll run
total_gross_payNUMERIC(12,2)Total gross payroll amount
statusVARCHAR(20)Payroll run status
Tablesbusinessespayroll_runs
Interviewer

Your question is Top Three Payroll Runs. Start with the requirements and the two 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.