I’d like to sum the total up and down votes on only the items bought by a single user. I have a big table so I don’t want to sum all votes made by everyone for EVERY item, just the items that a particular user bought.
Here’s my query so far:
select SUM(purchaseyesno) AS tots, SUM(rating=1) AS yes, SUM(rating=0) AS no, item_id
from items_purchased
where purchaser_account_id=12373
group by item_id
as you can expect, these sums are only the summing user 12373’s info, so its just one value. I’m not sure how to get ALL the purchases of item_ids that are bought by user 12373.
I’m sure there is some kind of subquery,nesting thing I need to include but I’m clueless.
here’s how I’d like my data to look, item_id=3,4,5 are all bought by user=12373. Whereas item_id=1,2,6 were bought by other users.
item_id tots yes no
3 7 4 2
4 5 1 3
5 1 0 1
thoughts?
1 Answer