Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
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
You need to log in / sign up to run or submit.Ln 1
Run your query to see results here.