Airport Name Lengths
Beginner Mode

Scenario

You are a data analyst at a major airline with three tables containing flight records, airport details, and plane specifications.

Task

Write a Snowflake SQL query that:

  1. Joins {{ ref("flights") }} to {{ ref("airports") }} twice (once for the origin airport, once for the destination airport) using table aliases
  2. Joins {{ ref("flights") }} to {{ ref("planes") }} on flight_id = plane_id
  3. Computes origin_airport_name_length as the length of the trimmed origin airport name
  4. Computes destination_airport_name_length as the length of the trimmed destination airport name
  5. Computes plane_model_length as the length of the trimmed plane model name
  6. Returns flight_id, origin_airport_name_length, destination_airport_name_length, and plane_model_length

Schema

flights

Column Type Description
flight_id Integer Unique flight identifier
origin_airport String Airport ID of the origin
destination_airport String Airport ID of the destination

airports

Column Type Description
airport_id String Unique airport identifier
airport_name String Full name of the airport (may have leading or trailing spaces)

planes

Column Type Description
plane_id Integer Unique plane identifier
plane_model String Model name of the plane (may have leading or trailing spaces)

Example

flights:

flight_id origin_airport destination_airport
1 JFK LAX
2 ORD MIA
3 SEA DFW
4 ATL SFO
5 BOS DEN

airports:

airport_id airport_name
JFK John F Kennedy
LAX Los Angeles
ORD Chicago OHare
MIA Miami
SEA Seattle Tacoma
DFW Dallas Fort Worth
ATL Atlanta
SFO San Francisco
BOS Boston Logan
DEN Denver

planes:

plane_id plane_model
1 Boeing 787
2 Airbus A321
3 Boeing 737
4 Embraer E190
5 Airbus A350

Expected Output:

flight_id origin_airport_name_length destination_airport_name_length plane_model_length
1 14 11 10
2 13 5 11
3 14 17 10
4 7 13 12
5 12 6 11

Note: Lengths are computed after trimming whitespace. For example, "John F Kennedy" has 14 characters, "Los Angeles" has 11, and "Boeing 787" has 10.

Quick Solution

Code Environment

Sign in or try as guest to run your code.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →