Advertisement
Guest User

Untitled

a guest
Oct 6th, 2015
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. select count(*) from cliente c
  2. where c.cpf_cnpj is null
  3. and exists (select 1 from situacao_cadastral sca where sca.id_cliente = c.id_cliente and sca.ativo = true)
  4. and id_empresa in (8, 10, 9, 37, 38, 163, 164)
  5. and ((c.data_ultima_alteracao >= '2015-10-02' and (data_ultima_alteracao_cam is null or c.data_ultima_alteracao > c.data_ultima_alteracao_cam))
  6. or exists (select 1 from contato_cliente cc where cc.id_cliente = c.id_cliente and cc.data_ultima_alteracao >= '2015-10-02')
  7. or exists (select 1 from cliente_segmento cs where cs.id_cliente = c.id_cliente and cs.data_ultima_alteracao >= '2015-10-02')
  8. or exists (select 1 from cliente_segmento cs inner join representante_segmento rs on cs.id_cliente_segmento = rs.id_cliente_segmento where cs.id_cliente = c.id_cliente and rs.data_ultima_alteracao >= '2015-10-02')
  9. or exists (select 1 from item_frota_cliente ifc where ifc.id_cliente = c.id_cliente and ifc.data_ultima_alteracao >= '2015-10-02'));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement