日期:2014-05-18 浏览次数:20609 次
UPDATE 表A set z=b.id from (select a.* from x as a where a.time in (select max(time)from x where type =x.type)) b where a.type = b.type
------解决方案--------------------
create table x(id int,type int,time datetime,filepath int) create table a(z int,type int,time datetime,filepath int) insert x select 1, 1, '2011-01-01 14:00:00',1 union all select 2, 1, '2011-01-01 17:00:00',2 union all select 3, 1, '2011-01-01 12:00:00',3 insert a select 0,1,null,null go update a set a.z=b.id,a.time=b.time,a.filepath=b.filepath from a join x b on a.type=b.type where b.time=(select max(time) from x where a.type=type) go select * from a go drop table x,a