0
Hello,
relating the following tables:
Contract table
tb_contrato
id
credor_id
num_contrato
Invoice Table
tb_fatura
id
contrato_id
num_fatura
dt_vencimento
valor
Parameters
credor = 1
valor inicial = 1
valor final = 99999
atraso inicial = 1
atraso final = 99999
Query
SELECT `contrato`.`num_contrato`
FROM `tb_contrato` `contrato`
JOIN `tb_fatura` `fatura` ON `fatura`.`contrato_id` = `contrato`.`id`
WHERE `tb_fatura`.`valor` >= valor_inicial
AND `tb_fatura`.`valor` <= valor_final
using the parameters, I need to count the number of contracts according to the above query, also I need to understand how I can filter the contracts using the days in arrears of the contract, comparing the expiration date of the invoice with today’s date!
In your query a contract will be listed more than once if you have more than one invoice that meets the conditions. To count the different contracts you must use the COUNT function with the DISTINCT clause, but I’m not entirely sure that’s what you want.
– anonimo
That’s exactly what’s going on, you’re listing one for each invoice and that’s not what I want. what really is I want to list only the amount of contracts that fit into the query parameters.
– Wagner Fillio
Yes, it is expected from the result of an INNER JOIN.
– anonimo
You can help me build the baby ?
– Wagner Fillio