Skip to content

Instantly share code, notes, and snippets.

@cqusyc
Created March 22, 2019 12:32
Show Gist options
  • Save cqusyc/50de043ed4ae6f80db7504b5014f154e to your computer and use it in GitHub Desktop.
Save cqusyc/50de043ed4ae6f80db7504b5014f154e to your computer and use it in GitHub Desktop.
[查询注册用户某等级的点击水壶分布] #BigQuery #MergeGarden
SELECT
A.user_pseudo_id,
sum(A.tap_count) as tap_count
FROM
(
SELECT user_pseudo_id, event_params.value.int_value AS tap_count, event_timestamp
FROM
`analytics_195246954.events_*` AS T,
T.event_params
WHERE
event_name = 'af_click_tap_button'
AND event_params.key = 'af_count'
AND _TABLE_SUFFIX BETWEEN '20181209' AND '20181210' /* 修改为从注册到要查询的留存日期范围 */
AND user_pseudo_id IN (
SELECT /* 查询新用户 */
DISTINCT user_pseudo_id
FROM
`analytics_195246954.events_*` AS T,
T.event_params
WHERE
event_name = 'first_open'
AND geo.country = 'United States' /* 修改为指定国家 */
AND platform = 'ANDROID'
AND _TABLE_SUFFIX BETWEEN '20181209' AND '20181209' /* 修改为激活日期范围 */
)
) AS A,
(
SELECT /* 查询最高菜品等级 */
user_pseudo_id, event_timestamp
FROM
`analytics_195246954.events_*` AS T,
T.event_params
WHERE
event_name = 'af_click_tap_button'
AND event_params.key = 'level'
AND event_params.value.int_value = 2
AND _TABLE_SUFFIX BETWEEN '20181219' AND '20181220' /* 修改为从激活到要查询的留存日期范围 */
) AS B
WHERE A.user_pseudo_id = B.user_pseudo_id AND A.event_timestamp = B.event_timestamp
GROUP BY user_pseudo_id /* 按伪用户id去重 */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment