本帖最后由 sweetBug 于 2013-12-08 21:02:45 编辑

解决方案 »

  1.   

    把 not exists 转换成 left join ..update a left join (select ... ) as c on a.id=c.id
    set a.x=1
    where c.id is null
      

  2.   

    谢谢你的帮助,我写出来这个SQL了:update user_address t inner join (
    select t.USER_ID, ifnull(sum(t.IS_DEFAULT), 0) isDefault 
    from user_address t where t.USER_ID = 'ifelse'
    group by t.USER_ID
    ) i on i.USER_ID = t.USER_ID
    inner join (
    select t.USER_ID, min(t.ADDRESS_ID) minAddressId 
    from user_address t where t.USER_ID = 'ifelse'
    group by t.USER_ID
    ) j on j.USER_ID = t.USER_ID
    set t.IS_DEFAULT = 1
    where i.isDefault <= 0 and j.minAddressId = t.ADDRESS_ID