Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Top Three Lanes Per Month
00:00
5 left

Top Three Lanes Per Month

MediumSQL · PostgreSQL

Problem

Phoenix International Freight Services wants to identify its busiest shipping lanes over the most recent rolling year. Write a SQL query that finds the top three complete origin-destination lanes for each month.

Output

  1. Return one row per qualifying lane and month with columns month, origin_port, destination_port, shipment_count, and lane_rank.
  2. Include shipments from the 12-month period beginning on the first day of the month 11 months before September 2026 and ending before October 2026. Exclude rows where either port is NULL.
  3. Rank lanes within each month by shipment count descending. Break ties alphabetically by origin port, then destination port. Return at most three lanes per month.
  4. Order the result chronologically by month and then by lane rank.

Schema

shipments
ColumnTypeDescription
shipment_idPKINTUnique shipment identifier
shipment_dateDATEDate the shipment was recorded
origin_portVARCHAR(100)Port where the shipment originated
destination_portVARCHAR(100)Port where the shipment is delivered
Tablesshipments
Interviewer

Your question is Top Three Lanes Per Month. Start with the requirements and the one table 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.