与事件的两个条件匹配的查询 ID - BigQuery
Posted
技术标签:
【中文标题】与事件的两个条件匹配的查询 ID - BigQuery【英文标题】:Query IDs that match two conditions for an event - BigQuery 【发布时间】:2018-04-26 19:21:47 【问题描述】:我想查询我的数据集(表)以获取包含 user_ids、日期、事件名称和事件参数键的列。我还指定我只想要“LeaveReview”事件。
fruit <- query_exec(
"SELECT user_dim.user_id, event.date, event.name, event_param.key,
FROM `table_201804*`,
UNNEST(event_dim) as event,
UNNEST(event.params) as event_param
WHERE event.name = 'LeaveReview'
AND _TABLE_SUFFIX BETWEEN '01' AND '25'
LIMIT 40",
project = "my_table"
)
我将如何修改我的代码以仅获取在给定日期同时执行“LeaveReview”和“ClickFavorite”的用户的信息?我尝试了以下方法,但这不起作用:
fruit <- query_exec(
"SELECT user_dim.user_id, event.date, event.name, event_param.key,
FROM `table_201804*`,
UNNEST(event_dim) as event,
UNNEST(event.params) as event_param
WHERE (event.name = 'LeaveReview' AND event.name = 'ClickFavorite')
AND _TABLE_SUFFIX BETWEEN '01' AND '25'
LIMIT 40",
project = "my_table"
)
如果我执行以下操作,我会得到执行事件“ClickFavorite”的人,而不是事件“LeaveReview”或其他方式的人:
fruit <- query_exec(
"SELECT user_dim.user_id, event.date, event.name, event_param.key,
FROM `table_201804*`,
UNNEST(event_dim) as event,
UNNEST(event.params) as event_param
WHERE (event.name = 'LeaveReview' OR event.name = 'ClickFavorite')
AND _TABLE_SUFFIX BETWEEN '01' AND '25'
LIMIT 40",
project = "my_table"
)
【问题讨论】:
【参考方案1】:嗯。这样的事情有用吗?
SELECT user_dim.user_id
FROM `table_201804*`,
UNNEST(event_dim) as event,
UNNEST(event.params) as event_param
WHERE event.name IN ('LeaveReview', 'ClickFavorite')
GROUP BY user_dim.user_id
HAVING COUNT(DISTINCT event.name) = 2;
【讨论】:
我仍然想要所有其他信息,例如事件名称、日期和密钥,但我不能包含它们,因为它会给我一个警告“错误:SELECT 列表表达式引用事件。既不分组也不聚合的名称”以上是关于与事件的两个条件匹配的查询 ID - BigQuery的主要内容,如果未能解决你的问题,请参考以下文章