在PLSQL Server中使用子查询更新查询
我比较了Table1数据Table2数据,以及表1中不存在的过滤数据。我想让两个表行计数相等。为此,我需要在表2中设置is_Active = 0,其中表1中不存在数据。
示例::
UPDATE table2
SET table2.is_active = 0
WHERE (SELECT table2.user_name
FROM table2
WHERE table2.is_Active = 1
AND table2.user_name NOT IN (SELECT table1.user_name
FROM table1
WHERE table1.is_Active = 1));
==table1== ==table2==
'A', 'B', 'C' 'A', 'B', 'C'
'A', 'E', 'C' 'M', 'N', 'O'
'A', 'E', 'D' 'A', 'E', 'D'
'A', 'E', 'D'
在上面的示例中,表1和Table2包含相似的数据,除了'm','n','o',我希望将此行设置为is_Attive = 0状态。
I compared table1 data table2 data, and filtered data which was not existed in table1. I want to make both tables rows count equal. For that, I need to set is_active = 0 in table2, where the data was not existed in table1.
Example::
UPDATE table2
SET table2.is_active = 0
WHERE (SELECT table2.user_name
FROM table2
WHERE table2.is_Active = 1
AND table2.user_name NOT IN (SELECT table1.user_name
FROM table1
WHERE table1.is_Active = 1));
==table1== ==table2==
'A', 'B', 'C' 'A', 'B', 'C'
'A', 'E', 'C' 'M', 'N', 'O'
'A', 'E', 'D' 'A', 'E', 'D'
'A', 'E', 'D'
In above example, table 1 and table2 contains similar data except 'M', 'N', 'O', I want set this row into is_active = 0 state.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对我来说,不存在更新似乎是一种选择。
示例数据:
更新:
结果:
To me, update with not exists seems to be one option.
Sample data:
Update:
Result: