【问题标题】:operand should contain 1 columns [duplicate]操作数应包含 1 列 [重复]
【发布时间】:2012-11-26 16:54:30
【问题描述】:
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 列

有什么想法吗?

【问题讨论】:

    标签: mysql sql phpbb mysql-error-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
    );
    

    【讨论】:

    • 我正在尝试使用相同风格的声明,但使用 DELETE。有什么方法可以在我的子查询中选择多行? MySQL 不断向我抛出 1241 错误。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-31
    • 2014-06-08
    相关资源
    最近更新 更多