SQL Tutorial

Sorting and Grouping 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

Sorting

  1. Sort flights (all columns) by departure delay
  1. Sort flights (all columns) by descending arrival delay
  1. Sort weather data (all columns) by descending visibility and then descending wind speed

Grouping

  1. Group flights by origin and show each origin along with its average arrival delay as avg_arr_delay
  1. Group flights by destination and show each dest with its count of flights as total_flights, only for destinations having more than 100 flights