Oracel数据库:
表T1:t1id coid count
表T2:t2id coid date countt1id和t2id分别为两表主键,coid为相关记录编号,date为日期型字段,t2表中同一coid有多条不同时间录入(date不同)的记录。我想写一个游标来把t1表中count列更新为t2表中coid相同并且时间最晚的count内容。游标该怎么写啊?帮帮忙吧...我不会写.....

解决方案 »

  1.   

    用什么游标啊,直接update语句,一句就够了
      

  2.   

    表T1里面有多条记录,每条都要通过表T2里面的内容来更新最新的,直接update应该实现不了吧~?
      

  3.   

    update t1 
        set t1.count=
           ( select count
             from
             (select t2.*
               from t2
               where t2.t2id=t1.t1id
               order by t2.date desc
              )
             where rownum=1)
    where exists
    (
    select 1
    from t2 where t2.t2id=t1id)
      

  4.   

    游标的性能肯定没一句update语句效率高