UPDATE t_name t1  
   SET t1.t_name.status =   t2.status 
 WHERE exists 
(select  t2.id from (select c.id , a.status from t_seae a,t_name c where  c.id = a.id and c.status =   '考试  ' and a.time is not null and a.time = (select max(b.time) from t_seae b where a.id=b.id   ) ) t2 where t1.id=t2.id); 
其实就是想用  一个表中字段的值  去更新  别一个表中字段的值         想是这么写   但 SET t1.t_name.status =   t2.status          这里不认t2这个表    想问问  我应该怎么写呢?  谢谢了

解决方案 »

  1.   

    update t_name t1
       set t1.t_name.status=(select status from (select t2.status from t_seae t2 where t2.id=t1.id and t2.time is not null order by time desc) where rownum=1)
       where t1.status='考试';
    说明:
    1.用了8分心思,没有实机测试返回的结果集是否满足楼主要求
    2.status='考试'这个条件提到最外面是因为:原sql中c表与t1表是同一张表,这样写大幅提高性能。
    3.使用了rownum伪列,减少了访问次数,大幅提高了性能。
      

  2.   

    UPDATE t_name t1   
       SET t1.t_name.status =  (select  t2.status  from 
       (select c.id , a.status from t_seae a,t_name c 
    where  c.id = a.id and c.status =    '考试   ' 
    and a.time is not null and a.time = 
    (select max(b.time) from t_seae b where a.id=b.id   ) ) t2 whre t1.id=t2.id)where exists 
    (select 'a' from (select c.id , a.status from t_seae a,t_name c 
    where  c.id = a.id and c.status =    '考试   ' 
    and a.time is not null and a.time = 
    (select max(b.time) from t_seae b where a.id=b.id   ) ) tt where t1.id=tt.id)