SQL Tutorial

Transforming Techniques

📚 Schema reference · PNW flights 5 tables
airlines
  • carrier
  • name
airports
  • faa
  • name
  • lat
  • lon
  • alt
  • tz
  • dst
  • tzone
flights
  • year
  • month
  • day
  • dep_time
  • sched_dep_time
  • dep_delay
  • arr_time
  • sched_arr_time
  • arr_delay
  • carrier
  • flight
  • tailnum
  • origin
  • dest
  • air_time
  • distance
  • hour
  • minute
  • time_hour
planes
  • tailnum
  • year
  • type
  • manufacturer
  • model
  • engines
  • seats
  • speed
  • engine
weather
  • origin
  • year
  • month
  • day
  • hour
  • temp
  • dewp
  • humid
  • wind_dir
  • wind_speed
  • wind_gust
  • precip
  • pressure
  • visib
  • time_hour

Transforming

  1. Categorize flights by distance as Short, Medium, or Long. Use ‘Short’ for distances less than 500 miles, ‘Medium’ for 500 to 2000 miles, and ‘Long’ for more than 2000 miles. Show the distance column alongside the category as flight_distance_category.
  1. Calculate the average speed of flights grouped by origin and destination and order by the fastest average speed. Show origin, dest, and the average speed as avg_speed.

    To calculate the average speed, use the distance and air_time columns. Remember to convert air_time from minutes to hours for speed in miles per hour.