我正在使用MySQL版本5.我有两个表格,如下所示。
表1
From To Time TravelTime
表2
From To Time CongestionTime
我想实现以下输出。
如果两个表格中From
,To
和Time
相等,则分配TravelTime = CongestionTime
Table2 仅包含 Table1 中可用的From | To | Time
组合的子集。
答案 0 :(得分:1)
From是mysql保留字。如果您不想转义它,请将列名“From”更改为“TimeFrom”。
UPDATE table1,table2
SET table1.TravelTime=table2.CongestionTime
WHERE table1.From = table2.From
AND table1.To = table2.To
答案 1 :(得分:0)
Update Table1 Set Table1.TravelTime = Table2.CongestionTime
FROM Table2
WHERE Table1.From = Table2.From
AND Table1.To = Table2.To
AND Table1.Time = Table2.Time
答案 2 :(得分:0)
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