本文介绍了SQL UPDATE语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个查询,返回了我的ID
I have this query that returns me ids
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
但是我在此语句中遇到语法错误
but i'm getting syntax error with this statement
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
how do i update correctly ids that i retrieve from first statement
推荐答案
正确:
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 UPDATE语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!