I have this simple SQL SELECT that summarizes by ProductID but I get this “must appear” error.
SELECT Products.ProductID, Products.Qtty / Catalog.Fraction as Amount FROM Products, Catalog WHERE Catalog.ID = Products.ID GROUP BY Products.ProductID
SQL requires me to put column Fraction into GROUP BY clause which I do not need. I just need to summarize by ProductID. How do I build correct SQL statement here?
Thanks.
Advertisement
Answer
You need to use aggregate function:
SELECT Products.ProductID, SUM(Products.Qtty) / SUM(Catalog.Fraction) as Amount FROM Products JOIN Catalog ON Catalog.ID = Products.ID GROUP BY Products.ID