TABLE A
------------------------------------
A         B           C
91187    20090101     北京
91188    20090201     天津
91189    20090101     菏泽
91187    20090201     南昌
91188    20090301     太原
TABLE B
------------------------------------
A         B          
91187    CC1009       
91188    CC1010
91189    CC1011
91187    CC1012
91188    CC1013结果:
results:
--------------------------------------
A         B(车号)          C             D
CC1009    91187     20090201        南昌
CC1010    91188     20090301        太原
CC1011    91189     20090101        菏泽
CC1012    91187     20090201        南昌
CC1013    91188     20090301        太原意思是:根据B表中的A列进行关联,当B表中的A列B列不相同时,
当B中的A列和A中的A列相同时,取出A表中B列最大的数据,放到对应的车号所在的行中.

解决方案 »

  1.   

    try
    update tablea t1 
    set c=(select c from tablea t2 where b=(select max(b) from tablea where a=t2.a) and a=t1.a);
    update tablea t1 set b=(select max(b) from tablea where a=t1.a);
      

  2.   

    select c1,c2,c3,c4
      from 
    (select B.B c1,B.A c2,A.B c3,A.C c4,row_number()over(partition by B.B order by A.b desc) rn
      from A,B
     where A.A=B.A) aa
    where rn=1;
      

  3.   


    let me try it.thx