Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

SQL Week-Over-Week Late Increase

MediumSQL · PostgreSQL00:00
Practice interviewer
In session
5 left
00:00

Your question is SQL Week-Over-Week Late Increase. Start with the requirements and the two tables on the right.

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.

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
Your solutionPostgreSQL
You need to log in / sign up to run or submit.
Run a query to see results