← ham's website case studies
SQL Project

SFO Flight Capacity Analysis

A SQL case study using flight and aircraft tables to answer route-capacity questions with joins, filters, aggregates, and grouped results.

This project uses SQL to connect flight schedules with aircraft seating capacity, then answer practical questions about how many seats arrive at SFO from key routes and which aircraft types create the most capacity.

893 Flight records analyzed
34 Aircraft seat mappings
2,935 Total LHR to SFO seats
98 LAX to SFO flights

Project Question

If an airport, airline, or travel product team wanted to understand flight capacity into SFO, which routes and aircraft types would matter most? I used SQL to connect each flight to its aircraft seat count, then answered questions about total seats, maximum aircraft capacity, and flight frequency by aircraft type.

Live Query Demo

Click a query to see the same analysis logic run against a small embedded sample of the flight and aircraft data.

Route Capacity Simulator

Query

SELECT a query above to run it.

Result

WaitingChoose a query.

The demo is ready. It calculates results in the browser from sample route data.

Data Model

TableWhat It ContainsImportant Columns
flights One row per flight in the dataset. Origin, Destination, Flight, Aircraft, Stops, duration
aircrafts Aircraft code lookup table with seating capacity. Aircraft, Seats

Code & Findings

1. Create the SQL Tables

Setup
from sqlalchemy import create_engine, text

engine = create_engine("sqlite:///:memory:")
conn = engine.connect()

flights_df.to_sql("flights", conn, index=False, if_exists="replace")
aircrafts_df.to_sql("aircrafts", conn, index=False, if_exists="replace")

conn.execute(text("SELECT COUNT(*) FROM flights")).fetchone()
conn.execute(text("SELECT COUNT(*) FROM aircrafts")).fetchone()
Expand result and meaning
Flights table893 rows
Aircrafts table34 rows

The first step was validating that both tables loaded correctly. This matters because every later query depends on joining flight records to the aircraft seat lookup table.

2. Total Seat Capacity from London Heathrow to SFO

JOIN + SUM
SELECT
  COUNT(*) AS Flights,
  SUM(a.Seats) AS Total_Seats,
  ROUND(AVG(a.Seats), 1) AS Avg_Seats
FROM flights f
JOIN aircrafts a
  ON f.Aircraft = a.Aircraft
WHERE f.Origin = 'LHR'
  AND f.Destination = 'SFO';
Expand result and meaning
FlightsTotal SeatsAverage Seats
9 2,935 326.1

LHR to SFO is a high-capacity international route in this dataset. The average aircraft has more than 300 seats, which suggests this route is served by wide-body aircraft rather than smaller domestic planes.

3. Which Flights Make Up That London Capacity?

JOIN + DETAIL
SELECT
  TRIM(f.Flight) AS Flight,
  f.Aircraft,
  a.Seats
FROM flights f
JOIN aircrafts a
  ON f.Aircraft = a.Aircraft
WHERE f.Origin = 'LHR'
  AND f.Destination = 'SFO'
ORDER BY a.Seats DESC, Flight;
Expand result and meaning
FlightAircraftSeats
BA 285747347
BA 287747347
CO 8239744347
SQ 2519744347
VS 019744347
NZ 9831777300
NZ 9855777300
UA 931777300
UA 955777300

The capacity is split between 747/744 aircraft with 347 seats and 777 aircraft with 300 seats. Showing the detail rows makes the total explainable instead of leaving it as a black-box number.

4. Largest Aircraft Serving SFO from LHR or Frankfurt

FILTER + GROUP
SELECT
  f.Aircraft,
  a.Seats,
  f.Origin,
  COUNT(*) AS Flights
FROM flights f
JOIN aircrafts a
  ON f.Aircraft = a.Aircraft
WHERE f.Destination = 'SFO'
  AND f.Origin IN ('LHR', 'FRA')
GROUP BY f.Aircraft, a.Seats, f.Origin
ORDER BY a.Seats DESC, Flights DESC
LIMIT 5;
Expand result and meaning
AircraftSeatsOriginFlights
744347FRA6
744347LHR3
747347LHR2
777300LHR4

The largest aircraft serving SFO from these two origins have 347 seats. Frankfurt appears especially important for high-capacity 744 service in this dataset.

5. Cleaned Aircraft-Family Filter

Refinement
SELECT DISTINCT
  f.Aircraft,
  a.Seats
FROM flights f
JOIN aircrafts a
  ON f.Aircraft = a.Aircraft
WHERE f.Destination = 'SFO'
  AND f.Aircraft IN ('318', '319', '320', '32S', '346')
ORDER BY a.Seats DESC;
Expand result and meaning
AircraftSeats
346300
320150
32S150
319124

A first-pass aircraft-family filter used codes containing the number 3. An explicit code list is cleaner because it avoids accidentally including unrelated aircraft codes.

6. Flight Frequency from LAX to SFO by Aircraft Type

GROUP BY
SELECT
  Aircraft,
  COUNT(*) AS Number_of_Flights
FROM flights
WHERE Origin = 'LAX'
  AND Destination = 'SFO'
GROUP BY Aircraft
ORDER BY Number_of_Flights DESC, Aircraft;
Expand result and meaning
AircraftNumber of Flights
75219
31914
32014
73514
M8013
M838
7337
7343
CRJ3
7372
7391

The LAX to SFO route has 98 total flights in this dataset. Aircraft 752 appears most often, but frequency alone does not fully explain seat capacity, so I added a capacity-weighted query next.

7. Estimated LAX to SFO Seat Capacity by Aircraft Type

JOIN + CALC
SELECT
  f.Aircraft,
  COUNT(*) AS Flights,
  a.Seats,
  COUNT(*) * a.Seats AS Estimated_Seat_Capacity
FROM flights f
JOIN aircrafts a
  ON f.Aircraft = a.Aircraft
WHERE f.Origin = 'LAX'
  AND f.Destination = 'SFO'
GROUP BY f.Aircraft, a.Seats
ORDER BY Estimated_Seat_Capacity DESC;
Expand result and meaning
AircraftFlightsSeatsEstimated Capacity
752191823,458
320141502,100
M80131361,768
319141241,736
735141041,456

This is the strongest portfolio query because it turns a simple count into an operational insight. The 752 aircraft contributes the most estimated seat capacity on LAX to SFO because it combines high frequency with a larger seat count.

What This Shows

Technical Skills

  • Created and loaded SQL tables from CSV data
  • Joined related tables using aircraft codes
  • Used aggregate functions like COUNT, SUM, AVG, and MAX
  • Grouped and ordered query results for comparison
  • Refined an early query to make the logic more accurate

Product / Business Skills

  • Translated raw data into route-capacity questions
  • Connected query results to practical airport or airline decisions
  • Explained findings in plain English
  • Separated frequency from true passenger capacity
  • Used results to identify which aircraft types matter most