Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
SQL Week-Over-Week Late Increase
00:00
5 left

SQL Week-Over-Week Late Increase

MediumSQL · PostgreSQL

Problem

Write a SQL query to identify facilities with the largest week-over-week increase in late packages.

Use the provided facility and package event data. Compare consecutive calendar weeks, include weeks with zero late packages, and return every facility tied for the largest increase.

Output

  1. One row per facility and week producing the maximum increase.
  2. Columns: facility_id, facility_name, week_start, late_packages, prior_week_late_packages, and increase.
  3. Order by increase descending, then facility_id ascending.

Schema

facilities
ColumnTypeDescription
facility_idPKINTUnique facility identifier
facility_nameVARCHAR(100)Facility name
regionVARCHAR(50)Operational region
package_events
ColumnTypeDescription
package_idPKBIGINTUnique package event identifier
facility_idINTFacility processing the package
delivered_dateDATEPackage delivery date
is_lateBOOLEANWhether the package was late
Tablesfacilitiespackage_events
Interviewer

Your question is SQL Week-Over-Week Late Increase. 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.