-
Notifications
You must be signed in to change notification settings - Fork 0
/
App Usage - Never Logged In
70 lines (70 loc) · 2.04 KB
/
App Usage - Never Logged In
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
WITH employers_users AS(
SELECT
CAST(
associations."users" #>> '{participant}' AS uuid
) AS user_id
FROM
associations,
users
WHERE
CAST(
associations.users #>> '{employer}' AS uuid
) = users.user_id
AND(users.display_name = <Parameters.Employer>)
AND users.deleted_at is null
AND associations.deleted_at is null
),
completedPO AS(
SELECT DISTINCT
ea.user_id,
e.start_date AS call_date
FROM
event_attendees ea JOIN events e ON e.id = ea.event_id
INNER JOIN employers_users e_u ON ea.user_id = e_u.user_id
WHERE
e.type = 'program_orientation' AND
e.status = 'completed' AND
e.deleted_at is null AND
ea.deleted_at is null
), appUsers AS (
SELECT DISTINCT
cpo.user_id
FROM
user_logs ul JOIN completedPO cpo ON ul.user_id = cpo.user_id
WHERE
ul.message ILIKE 'newtmobileapp navigation tracking%' AND
ul.deleted_at is null
),emails AS(
SELECT DISTINCT ON (ue.user_id)
ue.user_id as user_id,
ue.email as email
from completedPO au join user_emails ue on au.user_id = ue.user_id
where
ue.deleted_at is null
order by ue.user_id, ue.created_at DESC
),inspirators AS(
SELECT DISTINCT ON (ue.user_id, inspirator)
ue.user_id as user_id,
r.meta #>> '{first_name}' as firstName,
r.meta #>> '{last_name}' as lastName,
ue.email as email,
(select display_name from users where user_id = (a.users #>> '{coach}')::uuid) as inspirator
from completedPO au join user_emails ue on au.user_id = ue.user_id
join records r on au.user_id = r.user_id
join associations a on au.user_id = (a.users #>> '{participant}')::uuid
where
r.entity_id in (select id from entities where name = 'Intake') AND
a.type = 'coach:participant' AND a.deleted_at is null AND r.deleted_at is null and ue.deleted_at is null
order by ue.user_id, inspirator, ue.created_at DESC, a.created_at DESC
)
select
cpo.user_id,
cpo.email,
cpo.firstName,
cpo.lastName,
cpo.inspirator
from
appUsers dm
FULL OUTER JOIN inspirators cpo ON cpo.user_id = dm.user_id
where
dm.user_id is null