update a set col1=b.col1, col2=b.col2, ..... from tablea a inner join ( select t1.* from tableb t1 inner join ( select keycol1,keycol2,max(datecol) as datecol from tableb group by keycol1,keycol2 )t2 on t1.keycol1=t2.keycol1 and t1.keycol2=t2.keycol2 and t1.datecol=t2.datecol )b on a.keycol1=b.keycol1 and a.keycol2=b.keycol2
update 另一张表 set 另一张表.lastmodify=一张表.lastmodify from 一张表 where 另一张表.关键字=一张表.关键字
set col1=b.col1,
col2=b.col2,
.....
from tablea a inner join
(
select t1.*
from tableb t1
inner join
(
select keycol1,keycol2,max(datecol) as datecol
from tableb group by keycol1,keycol2
)t2
on t1.keycol1=t2.keycol1
and t1.keycol2=t2.keycol2
and t1.datecol=t2.datecol
)b
on a.keycol1=b.keycol1
and a.keycol2=b.keycol2
set 另一张表.lastmodify=一张表.lastmodify
from 一张表
where 另一张表.关键字=一张表.关键字
现在是用表A的数据去更新表B的数据,但是A的数据不一定比B的新,需要比较记录的更新日期表A和表B可能不在一个数据库中
set col1=a.col1,
col2=a.col2,
.....
from a
where a.id=b.id and a.lastmodify > b.lastmodify (日期比较大小可以这样吗?)