0
Hello,
Suppose I have a table tb_fatura
with the following fields and values:
id | transacao_id | valor | vencimento 1 | 1 | 1109.97 | 2020-02-19 2 | 1 | 10, | 2019-05-01
I want somar
the column valor
, calcular
the dias em atraso do vencimento
and order by the greatest delay.
With the query below I can even get some kind of result, but still not what I need:
SELECT *, SUM(valor) AS total, DATEDIFF(CURDATE(), vencimento) as atraso
FROM tb_fatura
WHERE transacao_id = 1
GROUP BY transacao_id
This brings me the following result:
id | transacao_id | valor | vencimento | total | atraso
1 | 1 | 1109.97 | 2020-02-19 | 1119.97 | 91
This does not suit me because I need to order for the biggest delay and even adding order by
, I couldn’t! Doing this is possible ?
I guess you need to add up the days of delay, don’t you? something like
SUM(DATEDIFF(CURDATE(), vencimento))
– Ricardo Pontual
I do not need to add up the days in delay, I only need to get the biggest delay! the sum must be made only for the value!
– Wagner Fillio
then
MAX
doesn’t work?– Ricardo Pontual