1

有两个表,它们之间的两列也相同

table1:
id, date

table2:
id, date

问题是,如何更新可以匹配 2 表中日期的表 2 的 id,这意味着,例如

update table2 set table2.id = table1.id Where table1.date = table2.date

谢谢

4

1 回答 1

3
update t2 set t2.id = t1.id 
from table2 t2
inner join table1 t1 on t1.date = t2.date

Edit

update t2 set t2.id = t1.id 
from table2 t2
inner join table1 t1 on t1.date = t2.date
where convert(date,t2.date)>'2013/01/01' --YYYY/MM/DD if your Date column is datetime.
于 2013-06-26T10:20:42.870 回答