Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select count(*) from cliente c
- where c.cpf_cnpj is null
- and exists (select 1 from situacao_cadastral sca where sca.id_cliente = c.id_cliente and sca.ativo = true)
- and id_empresa in (8, 10, 9, 37, 38, 163, 164)
- 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))
- or exists (select 1 from contato_cliente cc where cc.id_cliente = c.id_cliente and cc.data_ultima_alteracao >= '2015-10-02')
- or exists (select 1 from cliente_segmento cs where cs.id_cliente = c.id_cliente and cs.data_ultima_alteracao >= '2015-10-02')
- 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')
- 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