如何运行可以整理 2 个事件之间的唯一数据的 BigQuery 查询
Posted
技术标签:
【中文标题】如何运行可以整理 2 个事件之间的唯一数据的 BigQuery 查询【英文标题】:How to run a BigQuery query that can collate unique data between 2 events 【发布时间】:2019-08-19 11:22:29 【问题描述】:我正在尝试查询数据库以获取有关已完成 2 个操作的用户的数据。
例如:
event_1 = "clicked_on_feedback" : event_params.key = "rating"
event_2 = "burger_chosen" : event_params.key = "burger_type"
现在我想看看那些给出负面反馈的用户他们选择订购什么类型的汉堡? 如何为具有不同 param_keys 的不同事件执行此操作?
我能够获取给予负面评价的用户列表
SELECT user_id,event_name, param.value.string_value AS rating FROM `table.events_*`,
UNNEST(event_params) AS param
where event_name IN ("clicked_on_feedback")
AND event_timestamp >
UNIX_MICROS(TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 10 DAY))
AND param.key = "rating"
结果
user_id event_name rating
abcxxx clicked_on_feedback 1
abcdxx clicked_on_feedback 2
我如何为这组用户在相同的时间间隔内获得他们选择订购的汉堡类型?
预期:
user_id event_name_1 rating event_name_2 burger_type
abcxxx clicked_on_feedback 1 burger_chosen triple_decker
abcdxx clicked_on_feedback 2 burger_chosen cheesy_chicken
【问题讨论】:
我尝试了以下方法,但这没有返回结果 WITH L AS (SELECT user_id, event_name, param.value.string_value AS rating FROMtable.events_intraday_20190819
, UNNEST(event_params) AS param where event_name IN (" clicked_on_feedback") AND param.key = "rating") SELECT user_id, event_name, param2.value.string_value AS burger_type FROM table.events_intraday_20190819
, UNNEST(event_params) AS param2 WHERE event_name IN ("burger_chosen") AND param2.key = "burger_type " AND user_id IN (SELECT user_id FROM L)
。 .样本数据和期望的结果真的很有帮助。
【参考方案1】:
只需加入两个 SELECT
语句,您可以将它们定义为两个 CTE:一个用于 rating,另一个用于 burger_chosen。下面是一个未经测试的 SQL 查询,需要对表和字段进行必要的调整。
WITH rate AS
(SELECT user_id, event_name, param.value.string_value AS rating
FROM `table.events_*`, UNNEST(event_params) AS param
WHERE event_name IN ("clicked_on_feedback")
AND event_timestamp > UNIX_MICROS(TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 10 DAY))
AND param.key = "rating"
), brgr AS
(SELECT user_id, event_name, param.value.string_value AS burger_type
FROM `table.events_*`, UNNEST(event_params) AS param
WHERE event_name IN ("burger_chosen")
AND event_timestamp > UNIX_MICROS(TIMESTAMP_SUB(CURRENT_TIMESTAMP, INTERVAL 10 DAY))
AND param.key = "burger_type")
SELECT rate.user_id, rate.event_name AS event_name_1, rate.rating,
brgr.event_name AS event_name_2, brgr.burger_type
FROM rate
INNER JOIN brgr ON rate.user_id = brgr.user_id
【讨论】:
以上是关于如何运行可以整理 2 个事件之间的唯一数据的 BigQuery 查询的主要内容,如果未能解决你的问题,请参考以下文章
Power bi怎么关联数据表?Power bi如何关联数据表啊?求解!!!
国内唯一连续入选Gartner,Quick BI是如何做到的?
Hadoop 和 BI 如何结合?搭建一个基于 Hadoop+Hive 的数据仓库,它的前端展现如何实现?如何实现 BI?