gpt4 book ai didi

MySQL 选择其中行大于 1

转载 作者:行者123 更新时间:2023-11-29 14:49:59 25 4
gpt4 key购买 nike

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

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

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com