Мне нужно обновить все записи в таблице, для которой это значение не является частью какого-либо диапазона, хранящегося в другой таблице. Запрос, который обновляет записи, где он имеет значение , не является проблемой:
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
);