-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQRS_HIGIENIZACAO.sql
110 lines (92 loc) · 2.76 KB
/
QRS_HIGIENIZACAO.sql
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* /////// EDUARDO SOUSA - DATA ATUALIZAÇÃO 07/08/23 /////// */
/* [ETAPA 1] CONTATOS SEM CANAL ==> VOL. XXX.XXX ctts */
==> Nesta etapa basta criar um DataExtract via Automation Studio com o type 'Contact without Channel'
/* [ETAPA 2] CONTATOS DUPLICADOS ==> VOL. XXX.XXX ctts */
SELECT
SubscriberKey,
EmailAddress,
FLAG
FROM
(SELECT
SubscriberKey,
EmailAddress,
ROW_NUMBER() OVER (PARTITION BY EmailAddress ORDER BY CreatedDate DESC) AS FLAG
FROM _Subscribers
) A
WHERE FLAG >= 2
/* [ETAPA 3] CONTATOS COM "teste" no ENDEREÇO ==> VOL. XXX.XXX ctts */
SELECT
SubscriberKey,
EmailAddress
FROM _Subscribers
WHERE
EmailAddress LIKE 'teste%'
OR EmailAddress LIKE '%@teste%'
/* [ETAPA 4] ASSINANTES HARD BOUNCE ==> VOL. XX.XX ctts */
SELECT
s.SubscriberKey,
s.EmailAddress,
b.BounceCategory,
b.BounceSubcategory
FROM [_Bounce] b
INNER JOIN
[_Subscribers] s ON b.SubscriberKey = s.SubscriberKey
WHERE
b.BounceCategory = 'Hard Bounce'
OR
b.BounceSubcategory IN ('User Unknown', 'Domain Unknown', 'Inactive Account', 'Blocked', 'Unknow')
/* [ETAPA 5] CONTATOS COM CONTACTKEY IGUAL A TELEFONE => X.XXX ctts */
SELECT
smsSubLog.LogDate
, smsSubLog.SubscriberKey
, smsSubLog.MobileSubscriptionID
, smsSubLog.SubscriptionDefinitionID
, smsSubLog.MobileNumber
, smsSubLog.OptOutStatusID
, smsSubLog.OptOutMethodID
, smsSubLog.OptOutDate
, smsSubLog.OptInStatusID
, smsSubLog.OptInMethodID
, smsSubLog.OptInDate
, smsSubLog.Source
, smsSubLog.CreatedDate
, CONVERT(CHAR(10), smsSubLog.ModifiedDate,103) AS DateModifield
FROM
_SMSSubscriptionLog AS smsSubLog
WHERE
smsSubLog.SubscriberKey LIKE '%55%'
/*[ETAPA 6] CONTATOS COM CONTACTKEY IGUAL A EMAIL (se não for a padrão da BU) => X.XXX ctts*/
SELECT
SubscriberKey,
EmailAddress
FROM
_Subscribers
WHERE SubscriberKey LIKE '%@%'
/*[ETAPA 6 - NÃO APAGAR] ASSINANTES SEM ENVIO NOS ÚLTIMOS 6 MESES ==> VOL. XX.XXX ctts
=> Nesta etapa é interessante ter a volumetria de assinantes sem envio nos últimos 6 meses para sugerir uma Jornada de Winback/Recuperação de dormentes*/
SELECT
s.SubscriberKey,
s.SubscriberID,
s.EmailAddress,
s.Status,
s.Domain,
s.DateUndeliverable,
s.DateJoined,
s.DateUnsubscribed,
s.BounceCount,
s.SubscriberType,
s.Locale
FROM
[_Subscribers] s
WHERE
NOT EXISTS
(
SELECT
st.SubscriberKey
FROM
[_Sent] st
WHERE
s.SubscriberKey = st.SubscriberKey
)
AND
STATUS LIKE 'active'