gpt4 book ai didi

SQL更新语句

转载 作者:行者123 更新时间:2023-11-29 11:58:00 24 4
gpt4 key购买 nike

我有这个返回我 id 的查询

select id, default_code from product_product ou
where (select count(*) from product_product inr
where inr.default_code = ou.default_code) > 1 and ou.active = false

但是我在这条语句中遇到了语法错误

update product_product ou
where (select count(*) from product_product inr
where inr.default_code = ou.default_code) > 1 and ou.active = false set uo.default_code = uo.default_code || 'A';

ERROR: syntax error at or near "where"
LINE 2: where (select count(*) from product_product inr

如何正确更新从第一条语句中检索到的 ID

最佳答案

正确:

update
product_product ou
set
default_code = ou.default_code || 'A'
from
(
select default_code
from product_product
group by default_code
having count(*) > 1
) inr
where
not ou.active
and ou.default_code = inr.default_code

关于SQL更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55722522/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com