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
Window Function for Top Containers
00:00
5 left

Window Function for Top Containers

MediumSQL · PostgreSQL

Problem

Write a query using a window function to find the top three heaviest containers loaded onto each vessel at Mediterranean Shipping.

Use the vessel and container loading tables. Exclude containers whose weight is NULL. Assign distinct, deterministic positions by sorting heavier containers first and breaking equal-weight ties by container ID.

Output

  1. One row per selected container, with vessel_id, vessel_name, container_id, weight_kg, and weight_rank.
  2. Include up to three containers per vessel, ordered by vessel_id and weight_rank.

Schema

vessels
ColumnTypeDescription
vessel_idPKINTUnique identifier for the vessel
vessel_nameVARCHAR(100)Mediterranean Shipping vessel name
registry_portVARCHAR(100)Port where the vessel is registered
container_loads
ColumnTypeDescription
container_idPKINTUnique identifier for the container loading record
vessel_idINTVessel carrying the container
container_codeVARCHAR(20)Container identification code
weight_kgNUMERIC(10,2)Container gross weight in kilograms
Tablesvesselscontainer_loads
Interviewer

Your question is Window Function for Top Containers. 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
Sign up free to run your codeLog inLn 1
Run your query to see results here.