Skip to content

Instantly share code, notes, and snippets.

@dutchiechris
Created January 2, 2018 14:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dutchiechris/e6e136efaebefeeccb6444b8ed729cf6 to your computer and use it in GitHub Desktop.
Save dutchiechris/e6e136efaebefeeccb6444b8ed729cf6 to your computer and use it in GitHub Desktop.
Simple example of BigQuery (bq) sql join on airline public data set
SELECT
w.airline_name,
COUNT(departure_delay) AS delay
FROM
`bigquery-samples.airline_ontime_data.flights` AS f
JOIN (
SELECT
REGEXP_EXTRACT( airline ,r'.*: (.*)') as airline_code,
REGEXP_EXTRACT( airline ,r'(.*):.*') as airline_name
FROM
`bigquery-samples.airline_ontime_data.airline_id_codes`) AS w
ON
w.airline_code = f.airline
WHERE
departure_delay > 0
AND departure_airport = 'LGA'
AND date = '2008-05-13'
GROUP BY
w.airline_name
order by delay desc
LIMIT
100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment