View Full Version : Sum Query problem


Xerox
06-06-2002, 02:51 AM
Hi

I have a query which totals up the sales of
each product between 2 dates. The problem is that I am getting every entry for products sold between the 2 dates entered by the user.
What i need is total sales of each product between 2 dates without showing every entry (Just the totals of each product), the sql query being used at the moment is:

SELECT DISTINCTROW OrdersCalc.ProductID, Sum(OrdersCalc.ExtendedPrice) AS [Sum Of ExtendedPrice], Sum(OrdersCalc.Weight_kg) AS [Sum Of Weight_kg], Sum(OrdersCalc.Weight_lb) AS [Sum Of Weight_lb], Products.ProductDescription
FROM (OrdersCalc INNER JOIN Orders ON OrdersCalc.OrderID = Orders.OrderID) INNER JOIN Products ON OrdersCalc.ProductID = Products.ProductID
GROUP BY OrdersCalc.ProductID, Products.ProductDescription, Orders.OrderDate
HAVING (((Orders.OrderDate) Between [Enter1] And [Enter2]));

any ideas how i can acheive this.
Many Thanks for all help.

David R
06-06-2002, 08:03 AM
You've probably got too many fields in your query. Take out the fields that you're grouping by, or change the criteria fields to Where instead of Group By.

Pat Hartman
06-06-2002, 11:12 AM
Remove the DISTINCTROW keyword and change the Having to Where. Having criteria is applied AFTER the query is processed and since your Select does not include any dates (nor should it), your results will be invalid.

[This message has been edited by Pat Hartman (edited 06-06-2002).]

Xerox
06-07-2002, 05:54 AM
Guys thank you for your help, replacing the GroupBy to Where has solved the problem.