表A  字段 a,b,c.a,b为主键,c为记载时间的字符串
表B  字段 a,b,c.c为记载时间的字符串
其中表A和表B 是一对多关系.现在要实现的是:把表A中的c字段,修改为表B中符合(A.a = B.a and A.b = B.b)
条件的最大的c字段的值.
update (select max(b.c) as bc,A.c as ac,A.a from A,B 
where A.a = B.a and A.b = B.b group by ac,A.a ) set bc = ac
实现不了,哪位大虾给帮帮忙,谢谢.

解决方案 »

  1.   

    update A t1 set
         c = (select max(t2.c) from B t2 where t2.a = t1.a and t2.b = t1.b )
    where exists (select 'X' from B t3 where t3.a = t1.a and t3.b = t1.b)
      

  2.   

    update A set A.c=( select max(B.c) from A,B where A.a = B.a and A.b = B.b)
      where A.a=(select A.a from A,B where A.a = B.a and A.b = B.b)
      

  3.   

    update A set c = (select max(c) from B where A.a = B.a and A.b = B.b)
    where exists (select 1 from B where A.a = B.a and A.b = B.b)