1. 程式人生 > >update 同時更新多條屬性且同一個屬性的多個 值

update 同時更新多條屬性且同一個屬性的多個 值

   update sys_value t set 
   t.key = case t.key
          when 'xiao' then 'java' 
          when 'yong' then 'java'
          when 'jie' then 'java'
          else t.key end,
   t.value = case t.value
         when '1' then '2'
         when '2' then '3'
         when '3' then '4'
         when '4' then '5'
         else t.value end
   where t.id in (4,5,6,7)

當需要更新一個表中的多個屬性是,且一個屬性中需要修改多個值時,這是方法是最後的方法

有一個地方要注意

就是屬性中沒有加 else這個屬性時,沒比SQL修改的值將會比清空

解決辦法如圖片

歡迎大家討論留言