我是Bigquery的新手,似乎无法理解如何根据无法使用的数组计算字段。
我想基于与user_dim.user_properties.key相关联的值来计算和列出唯一用户,称为“persistent_user_id”。同时,我想在user_dim.user_properties.key中为另一个字段设置一个名为“status”的字段,其值为“Active”。
第一个条件: user_dim.user_properties.key =“persistent_user_id”,我希望计算存储在user_dim.user_properties.value.value.string_value中的唯一值
第二个条件: user_dim.user_properties.key =“status”和user_dim.user_properties.value.value.string_value =“Active”
此查询适用于根据“persistent_user_id”关联值列出用户,但我无法使其工作,因此它将“status”过滤器设置为“active”。这是我的疑问,非常感谢任何帮助。
SELECT
MAX(user_prop.key) AS keyname,
MAX(user_prop.value.value.string_value) AS user_id,
user_dim.app_info.app_instance_id AS app_id
FROM `tableName_*`, UNNEST (user_dim.user_properties) AS user_prop
WHERE user_prop.key = "persistent_user_id"
AND (_table_suffix >= '20180101') AND (_table_suffix <= '20180228')
GROUP BY app_id
我的查询使用标准SQL
答案 0 :(得分:2)
SELECT
MAX(uid.key) AS keyname,
MAX(uid.value.value.string_value) AS user_id,
user_dim.app_info.app_instance_id AS app_id
FROM
`tableName_*`,
UNNEST (user_dim.user_properties) AS uid,
UNNEST (user_dim.user_properties) AS status
WHERE
uid.key = "persistent_user_id"
AND status.key = "status"
AND status.value.value.string_value = "Active"
AND (_table_suffix >= '20180101')
AND (_table_suffix <= '20180228')
GROUP BY
app_id