Top Cost Categories
A medium SQL interview practice problem on DataDriven. Write and execute real sql code with instant grading.
- Domain
- SQL
- Difficulty
- medium
- Seniority
- L3
Problem
Categories are tracked in the budget allocation system (cost_allocs), but actual billing amounts live in the cost tracking system (cloud_costs). Attribute each cloud charge to its budget category by matching the allocation for the same service, region, and billing month (cloud_costs.bill_date's year-month equals cost_allocs.period). A (service, region) pair alone maps to several categories across months, so the month is required to make the attribution unambiguous; a service can also appear under several teams in the same period, so collapse (service, region, month) to one category before summing or each charge is counted multiple times. Show the top 3 categories by total attributed amount.
Summary
Three categories eating the budget.
Practice This Problem
Solve this SQL problem with real code execution. DataDriven runs your SQL queries against a real database and grades it automatically.