Advertisement
kirzecy670

Untitled

Dec 12th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.33 KB | None | 0 0
  1. WITH p_users AS (SELECT
  2.     distinct uid
  3. from
  4.     analytics.parent_properties
  5. where had_any_payment),
  6. ax AS (
  7.     SELECT
  8.         uid,
  9.         p_users.uid >= 'a' as flg_paid_user,
  10.         visitParamExtractRaw(addJson, 'block_name') AS blockName,
  11.         visitParamExtractString(addJson, 'index') AS index,
  12.         visitParamExtractString(addJson, 'type') AS type
  13.     FROM stat.funnelTrack left join p_users using(uid)
  14.     WHERE action = 'block_viewed'
  15.       AND dt >= today() - INTERVAL '14' day
  16. ),
  17. block_counts AS (
  18.     SELECT
  19.         index,
  20.         blockName,
  21.         type,
  22.         flg_paid_user,
  23.         uniqCombined(uid) AS n_user,
  24.         count(*) as n_event,
  25.         round(n_event/n_user,2) as per_user
  26.     FROM ax
  27.     WHERE index != ''
  28.     GROUP BY index, blockName, type, flg_paid_user
  29. ),
  30. ranked_blocks AS (
  31.     SELECT
  32.         blockName,
  33.         flg_paid_user,
  34.         cast(index as Int64) as index,
  35.         type,
  36.         n_user, n_event, per_user,
  37.         ROW_NUMBER() OVER (PARTITION BY index, flg_paid_user ORDER BY n_user DESC) AS rn
  38.     FROM block_counts
  39. )
  40. SELECT
  41.     index,
  42.     flg_paid_user,
  43.     blockName,
  44.     type,
  45.     n_user,
  46.     n_event,
  47.     per_user,
  48.     rn
  49. FROM ranked_blocks
  50. WHERE blockName != '"basementBanner"'
  51. having index <= 20
  52. and  rn <= 5
  53. ORDER BY flg_paid_user, index, n_user DESC;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement