我正在处理一个查询,该查询正在连接多个表以进行深入分析,以获取订阅者投票次数超过一个区域的订阅者数量。MySQL选择行大于1的行
我被困在的问题是试图在查询中计算订阅者投票超过一个的计算。
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
任何想法?
你能更清楚地解释你要找的是什么号码吗?如果子查询不能保证返回单个行,这将始终给出错误,因为它期望子查询中的字段名称。 – Mel 2011-05-11 20:16:54