![](/img/trans.png)
[英]How to Update bulk records in one table by finding the column's value existence in another table using Stored procedures?
[英]How to update records whose value is not in the ranges stored in another table
我需要更新其值不屬於另一個表中存儲的任何范圍的表中的所有記錄。 查詢更新記錄的值是范圍的一部分是沒有問題的:
update table_a
join table_range on
(table_a.x >= table_range.fromValue
and table_a.x <= table_range.toValue)
set table_a.someColumn = 'is in range'
但是我不知道如何更新以下查詢結果的記錄:
select *
from table_a
where x NOT IN (
select x
from table_a inner join table_range on
(x >= fromValue AND x <= toValue)
)
提前致謝
接下來呢?
drop table table_a;
drop table table_ranges;
create table table_a(
x int not null
,flag varchar(20)
);
create table table_ranges(
fromvalue int not null
,tovalue int not null
);
insert into table_a(x) values(10);
insert into table_a(x) values(20);
insert into table_a(x) values(30);
insert into table_ranges values(0,9);
insert into table_ranges values(10,19);
insert into table_ranges values(20,29);
update table_a a
set flag = 'not in range'
where not exists(
select *
from table_ranges r
where a.x between r.fromvalue and r.tovalue
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.