Skip to content
ML Academy

S02 · code review simulation

Review a network revenue query that NULLs quietly bend

People, data and outputs in this scenario are simulated. Each stage is recorded when you commit; the reveal comes after.

  • 4stages
  • 30 minabout
  • 0stages committed

The brief

An analyst (simulated) asks you to review a query before its numbers go into the 2023 network review deck. It runs on flight_day_raw in the course database (synthetic; grain intended to be one row per flight_no x date). Recall from Day 6 that the raw copy has about 0.8% duplicate rows (half of them with a late revenue update), missing avg_fare/revenue that is more common on intl-long, and a few impossible values.

SELECT market,
       COUNT(*)                                               AS flight_days,
       SUM(revenue)                                           AS revenue,
       ROUND(SUM(revenue) / SUM(capacity), 2)                 AS revenue_per_seat,
       ROUND(AVG(avg_fare), 2)                                AS avg_fare,
       SUM(CASE WHEN load_factor >= 0.95 THEN 1 ELSE 0 END) / COUNT(*) AS share_near_full
FROM flight_day_raw
WHERE date BETWEEN '2023-01-01' AND '2023-12-31'
GROUP BY market;

Its output (computed on the course database):

marketflight_daysrevenuerevenue_per_seatavg_fareshare_near_full
domestic400548,512,36969.3790.200
intl-long73091,047,541445.44602.940
intl-short219760,050,178157.71198.420

Stage 1 of 4

Review the query and its output before reading further.

Which problems do you flag? Select all that apply.

Sign in to play scenarios (answers are recorded before the reveal).