gpt4 book ai didi

sql - 将 SELECT 转换为更新语句

转载 作者:行者123 更新时间:2023-12-01 08:42:41 24 4
gpt4 key购买 nike

SELECT t1.status, t3.guid, t3.objectID
FROM Table1 t1, Table2 t2, Table3 t3
WHERE t2.ID = t3.ID
AND t1.ID = t2.ID
AND t3.Guid IN ('', '', '')

如何将其转换为更新语句,在其中设置 t1.status = 1 ?

最佳答案

我首先将其转换为使用连接而不是“经典连接”:

select t1.status, t3.guid, t3.objectID
from Table1 t1
inner join Table2 t2 on t2.ID = t1.ID
inner join Table3 t3 on t3.ID = t2.ID
where t3.Guid in ('', '', '')

然后你可以撕掉 select 语句并在它上面加上一个 update 和 set 语句:
update t1
set status = 1
from Table1 t1
inner join Table2 t2 on t2.ID = t1.ID
inner join Table3 t3 on t3.ID = t2.ID
where t3.Guid in ('', '', '')

关于sql - 将 SELECT 转换为更新语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/591360/

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