我有两个表我想从表 A 更新到表 B 。根据条件ID填空

Posted

技术标签:

【中文标题】我有两个表我想从表 A 更新到表 B 。根据条件ID填空【英文标题】:I have two tables I would like to update from table A to table B . Fills in the blanks according between condition ID 【发布时间】:2019-09-27 17:39:46 【问题描述】:

我有两张表我想从表 A 更新到表 B。根据条件 ID 填空。

表一

ID  color

1   red
2   
3   
4   
5   blue
6   
7   white
8   
9   
10  
11  
12  yellow
13  
14
15
16
17
18  

表b

color   from   to  
blue      5     6  
red       1     4  
white     7    11  
yellow   12    18  

【问题讨论】:

【参考方案1】:

您可以使用带有计算标准的连接来解决此问题,例如:

update t1 inner join t2 on (t1.id between t2.from and t2.to) set t1.color = t2.color

这与this recent question非常相似。

【讨论】:

以上是关于我有两个表我想从表 A 更新到表 B 。根据条件ID填空的主要内容,如果未能解决你的问题,请参考以下文章