Skip to content

Instantly share code, notes, and snippets.

@AdenForshaw
Created January 25, 2021 08:25
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 AdenForshaw/f6d236e230b3c73e67ab624e19174714 to your computer and use it in GitHub Desktop.
Save AdenForshaw/f6d236e230b3c73e67ab624e19174714 to your computer and use it in GitHub Desktop.
[BigQuery using parameterised query in the console]
DECLARE ORG_NAME STRING;
SET ORG_NAME = "AFL";
EXECUTE IMMEDIATE """
WITH x as
(
select
country
, category
, subcategory
, organisation
, id
from events_prod.mobile_apps
)
SELECT
country
, category
, subcategory
, organisation
, COUNT(DISTINCT id) as cnt_apps
, COUNT(1) AS cnt_rows
FROM x
cross join UNNEST(x.country) as country
WHERE organisation = @ORG_NAME
GROUP BY
country
, category
, subcategory
, organisation
"""
USING ORG_NAME as ORG_NAME;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment