Flag Projects Whose Billed Hours Exceed the Contracted Budget

Last updated: November 29, 2026

Quick Overview

Given `projects(project_id, client_name, budget_hours)` and `timesheets(entry_id, employee_id, project_id, work_date, hours, billable)`, return each project whose billable hours logged this calendar year exceed its budget, with the overrun in hours and as a percentage.

EPAM Systems
Data Manipulation (SQL/Python)
Data Engineer
EPAM Systems
November 29, 2026
Data Engineer
Technical Screen
Data Manipulation (SQL/Python)
Easy

0

0

0 solved


Given `projects(project_id, client_name, budget_hours)` and `timesheets(entry_id, employee_id, project_id, work_date, hours, billable)`, return each project whose billable hours logged this calendar year exceed its budget, with the overrun in hours and as a percentage.

Time tracking and budget burn are core to a delivery company like EPAM, so a SQL screen built on timesheets is a natural fit for data and backend candidates. The interviewer checks aggregation before joining, correct filtering of non-billable rows, and safe division.

What the Interviewer Expects
  • Filter to billable rows and the current year before aggregating
  • Aggregate timesheets per project first, then join to projects
  • Use HAVING (or an outer filter) on the aggregated sum
  • Guard division by zero or null budgets
  • Order results by overrun so the worst projects surface first
Key Topics to Cover
GROUP BY and HAVING
joins
date filtering
NULLIF
budget burn
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • How would you show projects that are above 90% of budget but not yet over?
  • How would you compute the week in which each project crossed its budget?
  • What changes if budgets are versioned with effective dates?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

One row per timesheet entry, hours is a decimal, billable is boolean. budget_hours is the total contracted hours and could be null or zero for time-and-materials projects, which should be exclud...

Approach

Aggregate first so the join is one row per project and no fan-out can inflate sums. Then compare against budget and compute overrun. Use NULLIF so a zero budget produces null rather than a division ...


Submit Your Answer
Markdown supported

Related Questions