当我运行此查询时,投票数sum
是应有的 2 倍(总和 = 6 而不是 3)。有人可以解决这个问题吗?
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
了 sum=3。但是,我需要在那里以某种方式加入。
想法?