我正在使用 MySQL 版本 5。我有两个结构如下所示的表。
表格1
From To Time TravelTime
表2
From To Time CongestionTime
我想实现以下输出。
如果From
,To
和Time
在两个表中都相等,则赋值TravelTime = CongestionTime
Table2仅包含Table1From | To | Time
中可用组合的子集。
from是mysql的保留字。如果您不想转义它,请将列名“From”更改为“TimeFrom”。
UPDATE table1,table2
SET table1.TravelTime=table2.CongestionTime
WHERE table1.From = table2.From
AND table1.To = table2.To
Update Table1 Set Table1.TravelTime = Table2.CongestionTime
FROM Table2
WHERE Table1.From = Table2.From
AND Table1.To = Table2.To
AND Table1.Time = Table2.Time
update table1
set traveltime = congestiontime
from table1
inner join table2 on table1.from = table2.from
and table1.to = table2.to
and table1.time = table2.time