I'm solving an exercise but I'm having problems with the return:
Question: Write the query that returns the vendor code, the vendor name, the number of products per vendor, and the average price for each vendor, only for vendors that have an average discount greater than 0.10. The result should be ordered by the average price.
Creating tables:
I need to return the select above, but I'm not getting it for 2 reasons:
Return the average price for each vendor using the AVG function (parameter).
Return the quantity of products per vendor, I'm using COUNT ().
My select so far:
SELECT f.codigo, f.nome, AVG(p.preco), COUNT(codfornecedor)
FROM produto as p
JOIN fornecedor as f
on codfornecedor = f.codigo AND p.desconto > 10 ORDER BY p.preco ASC
With the above selection method it is returning the average price of all fields, which I do not want, I need to return the average price of each supplier as well as their quantity of products.
Could someone help me with this query?