Sql 如何更新其值不在另一个表中存储的范围内的记录

Sql 如何更新其值不在另一个表中存储的范围内的记录,sql,mysql,Sql,Mysql,我需要更新一个表中的所有记录,它的值不属于另一个表中存储的任何范围。如果查询的值是某个范围的一部分,则更新该范围的记录不会有问题: 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' 更新表a 连接表\u范围上的 (table_a.x>=tab

我需要更新一个表中的所有记录,它的值不属于另一个表中存储的任何范围。如果查询的值是某个范围的一部分,则更新该范围的记录不会有问题:

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'
更新表a
连接表\u范围上的
(table_a.x>=table_range.fromValue

表a.x下面的内容如何

 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
  );

下面呢

 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
  );

就是这样!这正是我要找的。非常感谢!就是这样!这正是我要找的。非常感谢!