Skip to content

Instantly share code, notes, and snippets.

@savelee
Created February 22, 2017 09:45
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 savelee/13222587afc90483b552067e4469783e to your computer and use it in GitHub Desktop.
Save savelee/13222587afc90483b552067e4469783e to your computer and use it in GitHub Desktop.
BigQuery JOIN example
#standardSQL
#Top name frequency in Shakespeare
WITH TopNames AS (
SELECT
name,
SUM(number) AS occurrences
FROM
`bigquery-public-data.usa_names.usa_1910_2013`
GROUP BY
name
ORDER BY
occurrences DESC
LIMIT
100)
SELECT
name,
SUM(word_count) AS frequency
FROM
TopNames
JOIN
`bigquery-public-data.samples.shakespeare`
ON
STARTS_WITH(word,
name)
GROUP BY
name
ORDER BY
frequency DESC
LIMIT
10;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment