Created
November 11, 2016 21:04
-
-
Save primogf/c908b3ecaf4b1cfdb679d48f9b3c3428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select | |
pe.id_parceiro, | |
'VALE DA ESPERANCA' as nucleo, | |
concat('R$ ', MAX(cast(replace(replace(replace(replace(c.value,"R$","")," ",""),".",""),",",".") AS decimal(10,2)))) as valor_total_em_aberto, | |
DATE_FORMAT(NOW(),'%d/%m/%Y') as data_atualizacao_valor_total, | |
pe.uc, | |
pf.cpf as cpf_titular, | |
pf.nome as titular, | |
m.des as municipio, | |
pf.cpf as cpf_beneficiado, | |
pf.nome as beneficiado, | |
pe.endereco, | |
pe.numero, | |
pe.complemento, | |
b.des as bairro, | |
pe.cep | |
from | |
erp_parceiro_endereco pe | |
inner join erp_parceiro_pf pf on pf.id_parceiro = pe.id_parceiro | |
left join erp_parceiro_classificacoes c on pe.id_parceiro = c.id_parceiro and c.id_classificacao = 8 | |
inner join erp_municipio m on m.id_municipio = pe.id_municipio | |
inner join erp_bairro b on b.id_bairro = pe.id_bairro | |
where | |
pe.id_parceiro in ( | |
SELECT | |
id_parceiro | |
FROM | |
erp_parceiro_classificacoes | |
where | |
id_classificacao = 8 | |
and cast(replace(replace(replace(replace(value,"R$","")," ",""),".",""),",",".") AS decimal(10,2)) BETWEEN 150 AND 1000) | |
and cast(replace(replace(replace(replace(c.value,"R$","")," ",""),".",""),",",".") AS decimal(10,2)) BETWEEN 150 AND 1000 | |
group by pe.id_parceiro; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment