update my_rev_share_details_ntr2 a set a.revflag = 1 ,(a.entertime,a.exittime)=
(select b.entertime,b.exittime from stat_stay_june09 b where  a.call_time between b.entertime and b.exittime and b.staycause in (1,2,3) and a.imsi = b.imsi )
where  exists (select 1 from stat_stay_june09 b where a.call_time between b.entertime and b.exittime and b.staycause in (2,3) a.imsi = b.imsi);本句涉及个表 my_rev_share_details_ntr2 stat_stay_june09  里面都有上千万条数据 
表 my_rev_share_details_ntr2 a 主要字段: revflag entertime exittime imsi 
表 stat_stay_june09  b 主要字段: entertime exittime imsi staycause 
现在我想把表a的三个字段更新 当满足 a.call_time between b.entertime and b.exittime and b.staycause in (2,3) a.imsi = b.imsi时
希望高手能帮我提高这个句的效率 把语句写出来 十分感谢

解决方案 »

  1.   

    where  exists (select 1 from stat_stay_june09 b where a.call_time between b.entertime and b.exittime and b.staycause in (2,3) a.imsi = b.imsi);可以不要。还看你索引怎么建的。
      

  2.   

    ,where条件完全是多余的,楼主不妨试试下面的语句:
    update my_rev_share_details_ntr2 a set a.revflag = 1 ,(a.entertime,a.exittime)= 
    (select b.entertime,b.exittime from stat_stay_june09 b where  a.call_time between b.entertime and b.exittime and b.staycause in (2,3) and a.imsi = b.imsi ) 
      

  3.   

    对楼上说的有点疑问,如果不加where条件,如果在stat_stay_june09 中找不到满足条件的数据,那么my_rev_share_details_ntr2 中的entertime,exittime两个栏位将会以null来填充,而不会保留其原来的值。楼主是要这种效果吗?