update dl_ratio2 X set HZ='A' where HZ is Null and exists (select 'X' from DL_RATIO2 where X.order_code=order_code and HZ='A') ;即dl_ratio2中的order_code是可以重复的,我上面的语句的意图是,表中HZ字段为空的记录,如果有与它相同的Order_code的记录的HZ已经是‘A’,则这条记录的HZ也Update 为‘A’,但是不知为什么,在实际运行这条语句时,似乎一直在执行不会结束?

解决方案 »

  1.   

    你现在需要HZ is Null同时也要满足 HZ='A' 这两个条件不可能同时得到满足。。
      

  2.   

    我相当于把DL_RATIO2同时作为A表和B表,当B表的HZ='A'且B表的Order_code等于A表的Order_Code,且A表的HZ为NULL时,更新A表。
      

  3.   

    update dl_ratio2 A set HZ='A' where A.HZ is Null and exists (select 'X' from DL_RATIO2 B where B.order_code=A.order_code and B.HZ='A') ;
    或者写成这样的,也是一样一运行就卡死
      

  4.   

    update dl_ratio2 t1 
    set t1.HZ='A' 
    where t1.HZ is Null 
      and exists (select 1 from DL_RATIO2 t2 where t2.order_code=t1.order_code and t2.HZ='A' );-- 应该可以执行成功吧?