-
Notifications
You must be signed in to change notification settings - Fork 0
/
Прирост_и_отток_пользователей
39 lines (39 loc) · 1.14 KB
/
Прирост_и_отток_пользователей
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(
SELECT
this_week,
previous_week,
-uniq(user_id) as num_users,
status
FROM
(
SELECT
user_id,
groupUniqArray(toMonday(toDate(time))) as weeks_visited,
addWeeks(arrayJoin(weeks_visited), +1) as this_week,
if(has(weeks_visited, this_week) = 1, 'Оставшиеся пользователи', 'Ушедшие пользователи') as status,
addWeeks (this_week, -1) as previous_week
FROM simulator_20221020.feed_actions
GROUP BY 1
)
WHERE status = 'Ушедшие пользователи'
GROUP BY 1, 2, 4
HAVING this_week != addWeeks(toMonday(today()), +1)
)
union all
(
SELECT
this_week,
previous_week,
toInt64(uniq(user_id)) as num_users,
status
FROM
(SELECT
user_id,
groupUniqArray(toMonday(toDate(time))) as weeks_visited,
arrayJoin(weeks_visited) as this_week,
if(has(weeks_visited, addWeeks(this_week, -1)) = 1, 'Оставшиеся пользователи', 'Новые пользователи') as status,
addWeeks (this_week, -1) as previous_week
FROM simulator_20221020.feed_actions
GROUP BY 1)
GROUP BY 1, 2, 4
)