otavioguerra

Gera Campanha para Modelo

Jul 8th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Gera campanha para modelo
  2. WITH resultado AS (
  3.     SELECT DISTINCT
  4.      a.cpf
  5.     , a.salario
  6.     , a.margemdisponivel
  7.     , a.ratingportabilidade
  8.     , a.ratingnovo
  9.     , ratingrefin
  10.     FROM meutudo.cliente a
  11.         inner join meutudo.tb_telefone b ON b.cpf = a.cpf
  12.     WHERE 1 = 1
  13.     AND a.uf IN ( 'SC' )
  14.     AND a.ratingportabilidade > 36
  15.     AND b.ranking = '5'
  16.     AND b.flg_mobile = TRUE
  17.     AND ( b.flag_ativo <> FALSE OR b.flag_ativo IS NULL )
  18.     AND ( a.bloqueadosms <> TRUE OR a.bloqueadosms IS NULL )
  19.     ORDER BY a.ratingportabilidade DESC
  20. )
  21. SELECT cpf, salario, margemdisponivel, ratingportabilidade, ratingnovo, ratingrefin FROM resultado
  22. except
  23. (SELECT c.cpf, (SELECT cl.salario FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1)
  24. ,(SELECT cl.margemdisponivel FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1),
  25. (SELECT cl.ratingportabilidade FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1),
  26. (SELECT cl.ratingnovo FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1),
  27. (SELECT cl.ratingrefin FROM meutudo.cliente cl WHERE cl.cpf = c.cpf limit 1)
  28. FROM PUBLIC.mailing c )
  29. ;
Advertisement
Add Comment
Please, Sign In to add comment