-1
To calculate the mean no MySQL
we use the function AVG
.
This way you filter the payment method by the code, which in case is 6
:
SELECT a.`Tipo`, AVG(b.`ValorPagar`) AS media FROM FormaPagamento a
INNER JOIN Pagamento b ON a.`CodigoPagForm` = b.`CodigoFormaPagamento`
WHERE a.`CodigoPagForm` = 6
GROUP BY a.`Tipo`;
And this way you filter by type:
SELECT a.`Tipo`, AVG(b.`ValorPagar`) AS media FROM FormaPagamento a
INNER JOIN Pagamento b ON a.`CodigoPagForm` = b.`CodigoFormaPagamento`
WHERE a.`Tipo` = 'Boleto'
GROUP BY a.`Tipo`;
See more about the function AVG
here.
where is the purchase data? there is another table? you need to present the structure of the tables or it will be impossible to solve the problem
– rLinhares
see if you’ve improved
– Nathan Silva
In the title you say you have a problem... what is it? What did you try to do to calculate the average?
– Woss
I don’t know how to calculate the media, I’m asking how to do it.
– Nathan Silva
the average order paid by billet, I asked up there how I would do that, I have no idea how to do.
– Nathan Silva
paid by billet or by condition of payment ?
– Rovann Linhalis