操作数应包含1列

时间:2012-12-08 19:51:45

标签: mysql sql phpbb mysql-error-1241

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列

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您不应在COUNT(p.post_id) AS total_posts列表中的SELECT中包含子查询。 刚

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
);