小编典典

操作数应包含1列

sql

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列

有任何想法吗?


阅读 170

收藏
2021-04-14

共1个答案

小编典典

您不应该在子查询中包括COUNT(p.post_id) AS total_postsSELECT列表中。只是

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
);
2021-04-14