Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WITH p_users AS (SELECT
- distinct uid
- from
- analytics.parent_properties
- where had_any_payment),
- ax AS (
- SELECT
- uid,
- p_users.uid >= 'a' as flg_paid_user,
- visitParamExtractRaw(addJson, 'block_name') AS blockName,
- visitParamExtractString(addJson, 'index') AS index,
- visitParamExtractString(addJson, 'type') AS type
- FROM stat.funnelTrack left join p_users using(uid)
- WHERE action = 'block_viewed'
- AND dt >= today() - INTERVAL '14' day
- ),
- block_counts AS (
- SELECT
- index,
- blockName,
- type,
- flg_paid_user,
- uniqCombined(uid) AS n_user,
- count(*) as n_event,
- round(n_event/n_user,2) as per_user
- FROM ax
- WHERE index != ''
- GROUP BY index, blockName, type, flg_paid_user
- ),
- ranked_blocks AS (
- SELECT
- blockName,
- flg_paid_user,
- cast(index as Int64) as index,
- type,
- n_user, n_event, per_user,
- ROW_NUMBER() OVER (PARTITION BY index, flg_paid_user ORDER BY n_user DESC) AS rn
- FROM block_counts
- )
- SELECT
- index,
- flg_paid_user,
- blockName,
- type,
- n_user,
- n_event,
- per_user,
- rn
- FROM ranked_blocks
- WHERE blockName != '"basementBanner"'
- having index <= 20
- and rn <= 5
- ORDER BY flg_paid_user, index, n_user DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement