Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Top Facilities Maintenance Costs
00:00
5 left

Top Facilities Maintenance Costs

MediumSQL · PostgreSQL

Problem

Write a query to find the top three facilities by maintenance cost over the last quarter, partitioned by region.

For grading, treat the last quarter as April 1, 2025 through June 30, 2025. Include only facilities with the three highest totals in their region, with facility ID as the tie-breaker.

Output

  1. One row per selected facility, with region_name, facility_name, total_maintenance_cost, and facility_rank.
  2. Include up to three facilities per region, ordered by region_name, facility_rank, and facility_id.

Schema

regions
ColumnTypeDescription
region_idPKINTUnique regional identifier
region_nameVARCHAR(100)Region name
facilities
ColumnTypeDescription
facility_idPKINTUnique facility identifier
region_idINTRegion containing the facility
facility_nameVARCHAR(150)Facility name
maintenance_work_orders
ColumnTypeDescription
work_order_idPKINTUnique maintenance work order identifier
facility_idINTFacility receiving maintenance
maintenance_dateDATEDate of the maintenance work
maintenance_costNUMERIC(12,2)Cost of the maintenance work
Tablesregionsfacilitiesmaintenance_work_orders
Interviewer

Your question is Top Facilities Maintenance Costs. Start with the requirements and the three 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.