Find Active Employees Missing From Each Company's Latest Payroll
Last updated: November 29, 2026
Quick Overview
Using tables of employees, payroll runs and paystubs, list every employee who was employed during their company's most recent processed regular payroll period but has no paystub on that run.
Gusto
November 29, 20260
0
0 solved
Using tables of employees, payroll runs and paystubs, list every employee who was employed during their company's most recent processed regular payroll period but has no paystub on that run.
A missed paycheck is one of the most damaging errors a payroll provider can make, so Gusto's data and support teams care about catching an employee who was silently left off a run. This checks window functions, anti-joins and careful date logic around hires and terminations.
What the Interviewer Expects
- Picks exactly one latest run per company with a deterministic tie-break
- Filters to processed, regular runs and explains why off-cycle runs are excluded
- Defines employment overlap with the pay period correctly
- Uses a LEFT JOIN or NOT EXISTS anti-join
- Validates the result on known cases
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would you change this to cover the last three runs and only flag employees missing from the newest one but present in the earlier two?
- What if an employee was paid on an off-cycle run for that period instead, should they still be flagged?
- How would you exclude employees on unpaid leave?
- How would you turn this into a daily alert without flooding support with false positives?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
employees(id, company_id, hire_date, termination_date), payroll_runs(id, company_id, period_start, period_end, check_date, status, run_type), paystubs(run_id, employee_id). Assume salaried and h...
Approach
- Rank processed regular runs per company by
check_datedescending, breaking ties byid, and keep rank 1. - An employee is expected on that run if they were hired by the period end and not termi...