在程序中遇到這樣的需求, 數據庫表格式如下
需要把批量更新status, 如name = fox 時, status = 1, name = boa 時,status = 2 .... 類似的
postgres 的寫法如下:
update 表名 set status = case name when 'dodo' then '1' when 'eel' then '1' end where name in('dodo', 'eel');
在程序中遇到這樣的需求, 數據庫表格式如下
需要把批量更新status, 如name = fox 時, status = 1, name = boa 時,status = 2 .... 類似的
postgres 的寫法如下:
update 表名 set status = case name when 'dodo' then '1' when 'eel' then '1' end where name in('dodo', 'eel');
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。