Your question is SQL Subquery for Top Results. Start with the requirements and the three 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.
Maersk operations teams need to identify the busiest ports in the January 2026 reporting period. Write a PostgreSQL query that uses a subquery to return the top two ports by total container volume, measured in TEU.
port_calls, ports, and container_movements.2026-01-01 and 2026-01-31, inclusive.port_code as a deterministic tie-breaker.| Column | Type | Description |
|---|---|---|
| port_codePK | VARCHAR(10) | Maersk port code |
| port_name | VARCHAR(100) | Name of the port |
| Column | Type | Description |
|---|---|---|
| call_idPK | INT | Unique port call identifier |
| port_code | VARCHAR(10) | Port visited during the call |
| call_date | DATE | Date of the port call |
| status | VARCHAR(20) | Operational status of the call |
| vessel_name | VARCHAR(100) | Name of the vessel |
| Column | Type | Description |
|---|---|---|
| movement_idPK | INT | Unique movement identifier |
| call_id | INT | Related port call |
| container_id | VARCHAR(20) | Container identifier |
| teu | INT | Handled volume in twenty-foot equivalent units |