Reputation: 85
In a scheduled query in BQ, I am trying to filter countries using an external Google Sheet (already made a table). The query already has a join from two other tables. I would like to enter a SELECT clause in the WHERE statement.
SELECT
DATE(e_time) AS date,
DATE(i_time) AS i_date,
DATE_DIFF(DATE(e_time),DATE(i_time),day) AS days_since_install,
country_code AS country,
FROM
`data.sessions`
WHERE
DATE(e_time)= DATE_SUB(CURRENT_DATE(), INTERVAL 2 day)
AND country_code = (
SELECT
country_code as country
FROM
`data.sessions` a
INNER JOIN
`data.country_filter` b
ON
string_field_0 = a.country_code)
I keep getting errors. Any tips as to where I am going wrong? Expected output would be table 1 with the filtered countries from table b. Thank you in advance.
Upvotes: 0
Views: 462
Reputation: 32003
in your query you have to use in
SELECT
DATE(e_time) AS date,
DATE(i_time) AS i_date,
DATE_DIFF(DATE(e_time),DATE(i_time),day) AS days_since_install,
country_code AS country,
FROM
`data.sessions`
WHERE
DATE(e_time)= DATE_SUB(CURRENT_DATE(), INTERVAL 2 day)
AND country_code in(
SELECT
country_code as country
FROM
`data.sessions` a
INNER JOIN
`data.country_filter` b
ON
string_field_0 = a.country_code)
Upvotes: 2