Summing Totals in Query

DerekDaNoob

Registered User.
Local time
Tomorrow, 09:25
Joined
Dec 16, 2014
Messages
22
I am having trouble summing totals on a query

I need to group by IngredientID and have the total for that ingredient added up. Then sorted highest to lowest
 

Attachments

  • IMAG1113.jpg
    IMAG1113.jpg
    98.7 KB · Views: 162
Show us the SQL
You have something in the query that is wrong.
 
Thanks for the reply
Code:
SELECT [Meal - Recipes IngredientListQ].MealID, [Meal - Recipes IngredientListQ].IngredientID, [Meal - Recipes IngredientListQ].IngredientName, Sum([Meal - Recipes IngredientListQ].Qty) AS SumOfQty
FROM [Meal - Recipes IngredientListQ]
GROUP BY [Meal - Recipes IngredientListQ].MealID, [Meal - Recipes IngredientListQ].IngredientID, [Meal - Recipes IngredientListQ].IngredientName, [Meal - Recipes IngredientListQ].ID
ORDER BY [Meal - Recipes IngredientListQ].IngredientName, Sum([Meal - Recipes IngredientListQ].Qty) DESC;
 
Demonstrate your issue with data please. Provide 2 sets of data:

A: starting data from your table(s). Include table and field names and enough data to cover all cases.

B. expected results from A. Show what you expect to end up with when you feed in the data from A.
 
Remove the
GROUP BY [Meal - Recipes IngredientListQ].ID

you dont want to group this. ID shouldnt be in the query.
 
Try this:

SELECT [Meal - Recipes IngredientListQ].MealID, [Meal - Recipes IngredientListQ].IngredientID, [Meal - Recipes IngredientListQ].IngredientName, Sum([Meal - Recipes IngredientListQ].Qty) AS SumOfQty
FROM [Meal - Recipes IngredientListQ]
GROUP BY [Meal - Recipes IngredientListQ].MealID, [Meal - Recipes IngredientListQ].IngredientID, [Meal - Recipes IngredientListQ].IngredientName
ORDER BY [Meal - Recipes IngredientListQ].IngredientName, Sum([Meal - Recipes IngredientListQ].Qty) DESC;
 

Users who are viewing this thread

Back
Top Bottom