数据库
首页 > 数据库> > mysql-操作数应包含1列

mysql-操作数应包含1列

作者:互联网

这个问题已经在这里有了答案:            >            Operand Should Contain 1 Column – MySQL NOT IN                                    2个

SELECT topic_id
FROM phpbb_topics AS t
WHERE t.topic_id IN (
    SELECT p.topic_id, COUNT(p.post_id) AS total_posts
    FROM phpbb_posts AS p
    WHERE p.poster_id = 61640
    GROUP BY p.topic_id
    HAVING t.topic_replies_real = total_posts - 1
);

该查询给我以下错误:

错误代码:1241.操作数应包含1列

有任何想法吗?

解决方法:

您不应在子查询的SELECT列表中包括COUNT(p.post_id)个AS total_posts.
只是

SELECT topic_id   
FROM phpbb_topics AS t
WHERE t.topic_id IN (
    SELECT p.topic_id --, COUNT(p.post_id) AS total_posts 
    FROM phpbb_posts AS p
    WHERE p.poster_id = 61640
    GROUP BY p.topic_id
    HAVING t.topic_replies_real = COUNT(p.post_id) - 1
);

标签:sql,mysql,mysql-error-1241,phpbb
来源: https://codeday.me/bug/20191011/1891822.html