How to calculate the discount average in Mysql

Asked

Viewed 364 times

2

I need to calculate the discount average per product in my table in Mysql, but my code is only running on average, how can I get it to give me the product and the discount average on top of this product ?

source code:

SELECT avg(desconto) as media from object  
  • Alias, the question of exercise is this: What is the average value of discounts given per product. The columns present in the query result are: ID_PROD, MEDIA

1 answer

4


It’ll be something like this:

SELECT      ID_PROD
        ,   AVG(desconto) AS media 
FROM        object 
GROUP BY    ID_PROD
  • João, I don’t have the id_prod column, it would have to be printed as well as the media

  • If you want to average the discounts per product you have to have a product column to be able to group, otherwise you can’t! Put the table structure in your question.

  • tables are id_nt, id_item, cod_pro, value_unit, amount, discount`

  • It worked out, thanks

  • 2

    You are welcome! Give an UP and mark the answer as correct!

Browser other questions tagged

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