【发布时间】:2011-05-11 20:06:27
【问题描述】:
我正在处理一个查询,该查询将连接多个表以深入了解按订阅者拥有多于一票的地区投票的订阅者数量。
我遇到的问题是试图在查询中写出计算订阅者投票多于一个的位置。
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的错误
有什么想法吗?
【问题讨论】:
-
您能否更清楚地解释您要查找的号码?如果子查询不能保证返回单行,这总是会出错,因为它需要来自子查询的字段名。