同一个表中的多行用SQL中的大小写更新

时间:2015-10-29 10:44:09

标签: sql forms mysqli

我可以垂直更新我的数据库但是同时水平更新?

我的代码在这里

UPDATE energy SET nov = CASE
WHEN label = 'myLabel' THEN '123'
WHEN label = 'myLabel2' THEN '123'
ELSE nov
END WHERE uname='123' AND years='2558'

2 个答案:

答案 0 :(得分:0)

你的意思是连续多个傻瓜:

    UPDATE   energy
   SET   nov =
            CASE
               WHEN label = 'myLabel' THEN '123'
               WHEN label = 'myLabel2' THEN '123'
               ELSE nov
            END
       , nov2 =
            CASE
               WHEN label2 = 'myLabel' THEN '3123'
               WHEN label2 = 'myLabel2' THEN '3123'
               ELSE nov2
            END
 WHERE   uname = '123' AND years = '2558'

答案 1 :(得分:0)

你也可以这样做..

UPDATE energy
 SET nov =
(select  CASE
WHEN label = 'myLabel' THEN '123'
WHEN label = 'myLabel2' THEN '123'
ELSE nov
END  as case)
WHERE uname='123' AND years='2558'