このクエリを実行すると、投票sum
は本来あるべきものの 2 倍になります (3 ではなく合計 = 6)。誰かがこれの修正を理解できますか?
SELECT sum(votes.vote) AS sum
, my_votes.vote IS NOT NULL AS did_i_vote
, votes.parent_id, subject
, review_date
, item_id
, review_summary
, review, full_name
, reputation
, profile_picture
, accounts.acct_id
FROM votes
RIGHT JOIN items_purchased
on votes.parent_id=items_purchased.purchase_id
JOIN accounts
ON items_purchased.purchaser_account_id=accounts.acct_id
JOIN items
on items_purchased.item_id=items.folder_id
LEFT JOIN votes AS my_votes
ON my_votes.parent_id=items_purchased.purchase_id
AND my_votes.acct_id='3'
AND my_votes.column_name='purchase_id'
WHERE purchase_id='2'
AND deleted_p!=1 and pub_priv_p!=1
GROUP BY items_purchased.purchase_id
JOIN を取り除くとJOIN items on items_purchased.item_id=items.folder_id
合計 = 3 になるため、JOIN と関係があると確信しています。ただし、何らかの形でそのJOINが必要です。
考え?