MySQL 选择其中行大于 1

标签 mysql mysql-error-1242

我正在开发一个查询,该查询连接多个表以深入了解按订阅者拥有不止一票的区域进行投票的订阅者数量。

我遇到的问题是尝试在查询中写入计算订阅者投票超过一票的位置的计算结果。

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;

通过上述查询,我​​收到错误,子查询返回超过 1 行

有什么想法吗?

最佳答案

该部分

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

返回多个结果。尝试删除“GROUP BY votes.subscriber_id”,这应该可以解决问题

关于MySQL 选择其中行大于 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5969975/

相关文章:

MySQL:错误代码:1242 子查询返回超过 1 行

Mysql Multiple Concat Inner Join,只给出一个Name

mysql - SQL使用子查询从多个表中选择数据(包括来自内连接的数据)错误: 1242

Mysql "ON UPDATE"约束删除我的行

javascript - 在 Node.js 中使用 JS Promise 进行多个 mysql 调用

php - 如何使用 php mysql 在弹出窗口中显示记录

php - SQL SELECT 问题

php - 存储过程错误 :Subquery returns more than 1 rows

php - 添加或修改数组的一部分作为 mysql 字符串

php - 为什么播种机中的哈希方法与 Controller 中的哈希方法不同?拉维尔 5.1