1
Good afternoon, gentlemen, all right? I’m facing a problem and I can’t solve it.
Below is an example of my database structure:
I need to make a MYSQL script that selects people that contain the following conditions:
1 - PESSOA_ENDERECO.UF = "MS"
2 - PESSOA_EMPRESTIMO.DATA_TERMINO > NOW()
3 - PESSOA_EMPRESTIMO.TIPO_EMPRESTIMO = 'CARD'
4 - PESSOA_EMPRESTIMO.CODIGO_BANCO = '0001'
(that’s the part I’m not getting) 5 - HAVING A MARGIN AVAILABLE IN EXCESS OF A SPECIFIC PERCENTAGE;
The margin available shall be calculated as follows::
35% of the value found in PESSOA_BENEFICIO.VALUE less the sum of all VALOR_PARCELA of the benefit in question.
that is, if the person receives 1300 benefits, the margin is 455; the available margin of it would be 455 less the sum of all the installments of the loans that she owns.
Welcome to Stack Overflow! Please enter the query code you’ve created so far. This can help you find an answer.
– Andrei Coelho
I just got off work, tomorrow at the first time put the script I have so far!
– mguariero
select
pessoa
.* frompessoa_endereco
left Joinpessoa
onpessoa
.id
=pessoa_endereco
.pessoa_id
right Joinpessoa_emprestimo
onpessoa_emprestimo
.pessoa_id
=pessoa
.id
Wherepessoa_endereco
.estado
= 'MS' andpessoa_emprestimo
.banco
= '0001' andpessoa_emprestimo
.tipo_emprestimo
= 'CARD' group bypessoa_id
limit 10– mguariero