Advertisement
kirzecy670

Untitled

Jul 2nd, 2025 (edited)
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 3.45 KB | None | 0 0
  1. --//
  2. WITH
  3. -- Пользователи с ролью Owner
  4. owner_users AS (
  5.     SELECT user_id
  6.     FROM circles.circle_member
  7.     GROUP BY user_id
  8.     HAVING argMin(permission_role, id) = 'Owner'
  9. ),
  10. -- Пользователи с circles_concept_enabled
  11. with_flag AS (
  12.     SELECT DISTINCT user_id::UInt64 AS user_id
  13.     FROM stat.user_setting_history
  14.     WHERE name = 'circles_concept_enabled'
  15.       AND ts >= '2025-06-16'
  16.       AND value IN (1, '1', '"1"')
  17. ),
  18. -- Пользователи с ребиндами или reinstall
  19. reinstall_users AS (
  20.     SELECT DISTINCT uid
  21.     FROM stat.funnelTrack
  22.     WHERE dt >= '2025-01-01'
  23.       AND FMKIsAndroidParent(deviceType, appVersion)
  24.       AND (
  25.         (action IN ('bind_user', 'rebind_user')
  26.          AND visitParamExtractString(addJson, 'reason') IN (
  27.              'email', 'loginByEmailAndCode', 'restoreByAdId',
  28.              'adid', 'moveGlobalToRu', 'migration'))
  29.         OR action = 'reinstall_detected'
  30.       )
  31. ),
  32. -- circle_id из событий circle_concept_migration_pingo_joined_circle
  33. circle_concept_migration AS (
  34.     SELECT CAST(JSONExtractInt(addJson, 'circle_id') AS UInt64) AS circle_id
  35.     FROM stat.funnelTrack
  36.     WHERE dt >= '2025-06-01'
  37.       AND action = 'circle_concept_migration_pingo_joined_circle'
  38.     GROUP BY circle_id
  39. ),
  40. -- Пользователи, попавшие в circle_concept_migration
  41. circle_concept_migration_users AS (
  42.     SELECT DISTINCT cm.user_id AS user_id
  43.     FROM circles.circle_member cm
  44.     INNER JOIN circle_concept_migration u ON cm.circle_id = u.circle_id
  45. ),
  46. -- Пользователи, попавшие в parent_properties_fmk
  47. in_fmk AS (
  48.     SELECT id, full_reg_datetime::Date AS reg_date
  49.     FROM analytics.parent_properties_fmk
  50. ),
  51. -- Базовая когорта — все пользователи
  52. base_users AS (
  53.     SELECT
  54.         pp.id AS user_id,
  55.         pp.uid AS uid,
  56.         pp.full_reg_datetime::Date AS full_reg_date,
  57.         pp.children_quantity,
  58.         pp.platform,
  59.         pp.region
  60.     FROM analytics.parent_properties_v pp
  61.     JOIN owner_users ow ON ow.user_id = pp.id
  62. --    JOIN circle_concept_migration_users ccmu ON ccmu.user_id = pp.id
  63.     WHERE pp.full_reg_datetime >= '2025-06-01'
  64.       AND pp.full_reg_datetime < '2025-07-01'
  65.       AND pp.platform = 'Android'
  66.       AND pp.region = 'ru'
  67. ),
  68. -- Присоединяем фильтры и флаг FMK
  69. filtered AS (
  70.     SELECT
  71.         b.full_reg_date,
  72.         b.user_id,
  73.         b.uid as uid,
  74.         1 AS is_base,
  75.         IF(f.user_id != 0, 1, 0) AS has_flag,
  76.         IF(r.uid != '', 1, 0) AS is_reinstall,
  77.         IF(b.children_quantity >= 1, 1, 0) AS has_children,
  78.         IF(fmk.id != 0, 1, 0) AS is_in_fmk
  79.     FROM base_users b
  80.     LEFT JOIN with_flag f ON b.user_id = f.user_id
  81.     LEFT JOIN reinstall_users r ON b.uid = r.uid
  82.     LEFT JOIN in_fmk fmk ON b.user_id = fmk.id AND b.full_reg_date = fmk.reg_date
  83. )
  84. -- Агрегация
  85. SELECT
  86.     full_reg_date,
  87.     uniqExact(uid) AS base_users,
  88.     countIf(is_reinstall = 0) AS not_reinstall_users,
  89.     countIf(is_in_fmk = 1) AS fmk_id_users,
  90.     countIf(has_children = 1) AS with_children,
  91.     countIf(is_reinstall = 0 AND has_children = 1 AND is_in_fmk = 1) AS passed_filters,
  92.     countIf(has_flag = 1) AS newui_users,
  93.     countIf(is_reinstall = 0 AND has_children = 1 AND is_in_fmk = 1 AND has_flag = 1) AS passed_all_filters
  94. FROM filtered
  95. GROUP BY full_reg_date
  96. ORDER BY full_reg_date DESC LIMIT 30;
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement