sql - 使用每个 sql SELECT 结果,执行 UPDATE
问题描述
我正在尝试为此查询的每个结果编写一个 sql 查询:
select * from table2 where job_id = 'job1' and size=0
应将表 1 中的 job_id 设置为“00”。
到目前为止,我已经尝试过:
update table1 set job_id = '00'
where id from ( select * from table2 where job_id = 'job1' and size=0 )
我猜应该每个循环都有类似的东西?
解决方案
假设有一个类似于id
in的列table1
要与子查询的结果进行比较,您可以使用运算符IN
:
update table1
set job_id = '00'
where id in (select id from table2 where job_id = 'job1' and size = 0)
推荐阅读
- vue.js - 如何使用 Vue + Jest 模拟 axios 帖子
- javascript - I cannot apply javascript to Wordpress. Can you help me?
- java - as(Function ,P>transformer)有什么用
- c# - WPF 我可以更改路径形状上鼠标事件的灵敏度吗
- r - 缺少参数,没有默认值
- django - Django 信号:与从同一类继承的模型冲突
- c# - C# - 按对象的多个属性排序
- swift - 无法在 xctest 中导入主应用程序模块
- python - 使用 GroupBy 的条件格式
- c# - 如何将图标设置为“SelectEntity”表单?