欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

数据库批量查询结果作为更新的值

程序员文章站 2022-06-04 22:06:23
...

数据库批量更新。 业务需求: 需要将a表中 type为1 的数据的source_id更新为新的id。 因为之前的id是存储在p_server中,现在更新到了server_info表中 update a set source_id = s.server_id from (select p_server.p_id,p_server.index_code,server_info.ser

数据库批量更新。

业务需求:

需要将a表中 type为1 的数据的source_id更新为新的id。

因为之前的id是存储在p_server中,现在更新到了server_info表中

update a set source_id = s.server_id  from 
(select p_server.p_id,p_server.index_code,server_info.server_id 
from p_server join server_info 
on p_server.index_code = server_info.index_code) s where 
a.source_id = s.p_id
and type = 1;