gpt4 book ai didi

MYSQL:基数违规:1242 子查询返回超过 1 行?

转载 作者:行者123 更新时间:2023-11-29 18:19:13 24 4
gpt4 key购买 nike

我正在使用此查询来搜索标签相似性

SELECT sites_id
FROM tags_to_sites
WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
AND sites_id!= ?
GROUP BY sites_id
HAVING COUNT(*) = ( SELECT COUNT(*) FROM tags_to_sites
WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
AND sites_id!= ?
GROUP BY sites_id
ORDER BY COUNT(*) DESC LIMIT 3)

但我收到错误

SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row

有人知道为什么吗?

最佳答案

正确的查询

SELECT sites_id
FROM tags_to_sites
WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
AND sites_id!= ?
GROUP BY sites_id
HAVING COUNT(*) = ( SELECT COUNT(*) FROM tags_to_sites
WHERE tags_id IN (SELECT tags_id FROM tags_to_sites WHERE sites_id= ?)
AND sites_id!= ?
GROUP BY sites_id
ORDER BY COUNT(*) DESC LIMIT 1)
LIMIT 3

关于MYSQL:基数违规:1242 子查询返回超过 1 行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46739192/

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