Documentos de Académico
Documentos de Profesional
Documentos de Cultura
select distinct
idcampanha
,campanha
,idcliente
,canal
,status
,event_type
,min(event_timestamp) event_timestamp
,pinpoint_app_id
,pinpoint_campaign_id
from
ar_track_events
where
((pinpoint_app_id = %(pinpoint_app_id)s
and pinpoint_campaign_id = %(pinpoint_campaign_id)s)
or idcampanha = %(campanha_id)s)
group by
idcampanha
,campanha
,idcliente
,canal
,status
,event_type
,pinpoint_app_id
,pinpoint_campaign_id
)
select * from (
-------------------- ENVIADOS --------------------
select
'1-ENVIO' as tipo -- Comunicações enviadas ('send')
,count(distinct te.idcliente) clientes -->
Conta de forma distinta a quantidade de Shoppers
,0 faturamento
,0 compras
from
eventos te
where
te.idcliente is not null --> o
campo cliente = notNull
and split_part(te.event_type, '.', 2) = 'send' --> no
campo te.event_type ele pegará a palavra 'send'
union
where
te.idcliente is not null
and split_part(te.event_type, '.', 2) = 'send'
and status = 'SUCCESS'
union
where
te.idcliente is not null
and split_part(te.event_type, '.', 2) = %(ativacao)s -- ALTERAR
and (status = 'SUCCESS' or status is null)
union
where
dataconsumo >= event_timestamp
and date(dataconsumo) between %(data_min)s and %(data_max)s
and split_part(te.event_type, '.', 2) = %(ativacao)s -- ALTERAR
and te.idcliente is not null
and (status = 'SUCCESS' or status = 'DUPLICATE_ADDRESS' or status is null)
union
where
te.idcliente is not null
and split_part(te.event_type, '.', 2) = 'like' -- ALTERAR
union
select
'5.2-DESMARCOU GOSTEI' as tipo -- Clientes que desmarcaram "Gostei"
,count(distinct te.idcliente) clientes
,0 faturamento
,0 compras
from
eventos te
where
te.idcliente is not null
and split_part(te.event_type, '.', 2) = 'unlike' -- ALTERAR
union
where
te.idcliente is not null
and split_part(te.event_type, '.', 2) = 'remove' -- ALTERAR
order by
tipo