複数のテーブルを結合してドリルダウンし、サブスクライバーが複数の投票を持つ地域ごとに投票したサブスクライバーの数を取得するクエリに取り組んでいます。
私が立ち往生している問題は、購読者が複数回投票した場所の計算を計算するクエリを書き込もうとしていることです。
SELECT COUNT(*), regions.name,
(SELECT COUNT(*) FROM votes
LEFT JOIN profiles on votes.subscriber_id = profiles.subscriber_id
LEFT JOIN countries on profiles.country_id = countries.id
WHERE countries.region_id = regions.id GROUP BY votes.subscriber_id) as vote_count
FROM subscribers
LEFT JOIN profiles on subscribers.id = profiles.subscriber_id
LEFT JOIN countries on profiles.country_id = countries.id
LEFT JOIN regions on countries.region_id = regions.id
LEFT JOIN votes on subscribers.id = votes.subscriber_id
WHERE subscribers.created_at < '2011-04-22 00:00:00'
GROUP BY regions.id
HAVING vote_count > 1;
上記のクエリでは、次のエラーが表示されます。Subquery returns more than 1 row
何か案は?