I’m having problems with Mysql, I don’t know how to get media

Asked

Viewed 66 times

-1

I wanted to know the order average paid by billet on the Pay table, how I would do that?inserir a descrição da imagem aqui

  • 1

    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

  • see if you’ve improved

  • In the title you say you have a problem... what is it? What did you try to do to calculate the average?

  • I don’t know how to calculate the media, I’m asking how to do it.

  • the average order paid by billet, I asked up there how I would do that, I have no idea how to do.

  • paid by billet or by condition of payment ?

Show 1 more comment

2 answers

4


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.

  • thank you very much, I didn’t know that.

4

Averages :

Select codigo, AVG(valor) FROM Tabela 

Calculate the mean with target values:

Select codigo, AVG(DISTINCT valor) FROM Tabela

Calculates the average and sorts the result by the identifier(id):

Select codigo, AVG(valor) from Tabela GROUP BY codigo

Averages target values and sorts result by identifier(id):

Select codigo, AVG(DISTINCT valor) from Tabela GROUP BY codigo

Example by W3sshools.

Documentation Mysql.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.