1

我正在使用 MySQL 版本 5。我有两个结构如下所示的表。

表格1

From     To     Time     TravelTime

表2

From    To      Time     CongestionTime

我想实现以下输出。

如果From,ToTime在两个表中都相等,则赋值TravelTime = CongestionTime

Table2仅包含Table1From | To | Time中可用组合的子集。

4

3 回答 3

1

from是mysql的保留字。如果您不想转义它,请将列名“From”更改为“TimeFrom”。

UPDATE table1,table2
SET table1.TravelTime=table2.CongestionTime
WHERE table1.From = table2.From
AND table1.To = table2.To
于 2012-05-10T02:57:17.370 回答
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
于 2012-05-10T02:48:05.833 回答
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
于 2012-05-10T02:48:38.160 回答