Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Gera campanha para modelo
- WITH resultado AS (
- SELECT DISTINCT
- a.cpf
- , a.salario
- , a.margemdisponivel
- , a.ratingportabilidade
- , a.ratingnovo
- , ratingrefin
- FROM meutudo.cliente a
- inner join meutudo.tb_telefone b ON b.cpf = a.cpf
- WHERE 1 = 1
- AND a.uf IN ( 'SC' )
- AND a.ratingportabilidade > 36
- AND b.ranking = '5'
- AND b.flg_mobile = TRUE
- AND ( b.flag_ativo <> FALSE OR b.flag_ativo IS NULL )
- AND ( a.bloqueadosms <> TRUE OR a.bloqueadosms IS NULL )
- ORDER BY a.ratingportabilidade DESC
- )
- SELECT cpf, salario, margemdisponivel, ratingportabilidade, ratingnovo, ratingrefin FROM resultado
- except
- (SELECT c.cpf, (SELECT cl.salario FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1)
- ,(SELECT cl.margemdisponivel FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1),
- (SELECT cl.ratingportabilidade FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1),
- (SELECT cl.ratingnovo FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1),
- (SELECT cl.ratingrefin FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1)
- FROM PUBLIC.mailing c )
- ;
Advertisement
Add Comment
Please, Sign In to add comment