Reputation: 177
I'm trying to run a sql query for different ids. Something like
SELECT SUM(cost) FROM sales
WHERE id = "multiple ids"
I want the sum of the sales of each person separately but I can't seem to get it to work.
I tried using WHERE IN
but that returns a single query for the sum of everything.
Thanks in advance.
Upvotes: 0
Views: 36
Reputation: 122
Try using GROUP BY
to aggregate SUM(cost)
for each person.
SELECT id, SUM(cost) FROM sales
WHERE id IN (
1, 2, 3, 4
)
GROUP BY id
Upvotes: 1