[英]Filter country using a JOIN in BigQuery
In a scheduled query in BQ, I am trying to filter countries using an external Google Sheet (already made a table).在 BQ 的预定查询中,我正在尝试使用外部 Google 表格(已制作表格)过滤国家/地区。 The query already has a join from two other tables.
该查询已经有来自其他两个表的连接。 I would like to enter a SELECT clause in the WHERE statement.
我想在 WHERE 语句中输入 SELECT 子句。
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.
预计 output 将是表 1,其中包含表 b 中的过滤国家/地区。 Thank you in advance.
先感谢您。
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.