Suppose I'm given a table of the following format named Store:
Product: NumSold:
Mushroom 2
Ham 6
Apple 6
Mushroom 8
Ham 10
Apple 5
In plain language, I want to find the total number of each product sold. In more technical terms, I want to take each unique entry in the "Product" column and sum up the matching entry in the "NumSold" column. The desired result is as follows:
Mushroom 10
Ham 6
Apple 11
(In any order of course.)
I don't know if there's a technical term for this kind of summing so I've not been able to effectively Google for an answer. But I tried a query like the following:
SELECT Product, SUM(NumSold) FROM Store;
And got:
Apple 37
Which isn't the desired result. Is there any way to get my desired result in SQLite? (Keep in mind the tables I'm working with contain far more entries than this example.) Thanks.
Aucun commentaire:
Enregistrer un commentaire