SQL Tutorial

Filtering 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

Filtering rows/records

Capitalization matters when you match text with =. The flights database stores manufacturers in capitals ('BOEING'), airport codes in capitals ('SEA'), and time zones as written ('America/New_York'); manufacturer = 'Boeing' returns no rows. Type the value exactly as the data has it. LIKE is the exception in SQLite: it ignores capitalization for plain letters.

  1. Select the tail numbers (tailnum) and models (model) of Boeing planes from the planes table. The manufacturer is stored in capitals as ‘BOEING’.
  1. Select airports (faa, name, lat) above 40 latitude and in the America/New_York time zone.
  1. Select airports (faa code, name, and lat) within 40 to 42 degrees latitude.

Filtering text

  1. Select airlines (carrier code and name) with name starting with an “A”
  1. Select the tail numbers (tailnum) of flights having 101 as the second, third, and fourth characters of the tail number.
  1. Select flights (all columns) where the carrier is either “AS” or “HA”
  1. Select weather records (all columns) where wind direction is missing
  1. Select weather records (all columns) where temperature is not missing