简体   繁体   English

“标量子查询产生多个元素”

[英]"Scalar subquery produced more than one element"

I need to update a column's value by simply inserting a column of values according to another table in this way:我需要通过以这种方式根据另一个表简单地插入一列值来更新列的值:

UPDATE `inbound-summit-278521.MET689.fact_posts`
SET `inbound-summit-278521.MET689.fact_posts`.accepted = 
(SELECT (CASE WHEN id IN (SELECT T2.id
FROM `inbound-summit-278521.MET689.fact_posts` T1
JOIN `inbound-summit-278521.MET689.fact_posts` T2
ON T1.accepted_answer_id = T2.post_id)
THEN 1 ELSE 0 END)
FROM `inbound-summit-278521.MET689.fact_posts`)
WHERE `inbound-summit-278521.MET689.fact_posts`.accepted IS NULL;

The output error is shown as the title goes but no syntax error was detected.输出错误显示为标题,但未检测到语法错误。 What did it go wrong?出了什么问题? How should I fix it?我该如何解决?

It is really hard to tell what you are trying to do.很难说你想要做什么。 It seems to be that you want to set a flag to 1 if a corresponding row exists in the same table based on an "answer".如果基于“答案”在同一个表中存在相应的行,您似乎想将标志设置为1

If so, you can use a correlated subquery.如果是这样,您可以使用相关子查询。 Something like this:像这样的东西:

UPDATE `inbound-summit-278521.MET689.fact_posts` fp
    SET accepted = 1
    WHERE fp.accepted IS NULL AND
          EXISTS (SELECT 1
                  FROM `inbound-summit-278521.MET689.fact_posts` fpa
                  WHERE fpa.accepted_answer_id = fp.post_id
                 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM