日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

Update语句:使用case when按条件批量更新

發布時間:2025/7/14 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Update语句:使用case when按条件批量更新 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

為什么80%的碼農都做不了架構師?>>> ??

示例場景:

(1) 數據表table_001中有如下字段:column_01,?column_02,?column_03,?column_04

(2) 由于業務變更,增加了如下字段:column_10,?column_11,?column_12,?column_13

(3) 對于之前表中存在的記錄,需要根據“column_01,?column_02,?column_03,?column_04”的字段值,來填充"column_10,?column_11,?column_12,?column_13"的值。

?

示例語句:

update table_001?
?? ?set column_01 =?
?? ??? ?(case when column_10=0 then 0
?? ??? ? when column_10<120 then 1
?? ??? ? when column_10>=120 and column_10<140 then 2
?? ??? ? when column_10>=140 and column_10<160 then 3
?? ??? ? when column_10>=160 and column_10<180 then 4
?? ??? ? when column_10>=180 then 5
?? ??? ? end),
?? ??? ?column_02 =
?? ??? ?(case when column_11=0 then 0
?? ??? ? when column_11<80 then 1
?? ??? ? when column_11>=80 and column_11<90 then 2
?? ??? ? when column_11>=90 and column_11<100 then 3
?? ??? ? when column_11>=100 and column_11<110 then 4
?? ??? ? when column_11>=110 then 5
?? ??? ? end),
?? ??? ?column_03 =?
?? ??? ?(case when column_12=0 then 0
?? ??? ? when column_12<140 then 1
?? ??? ? when column_12>=140 then 2?? ?
?? ??? ? end),
?? ??? ?column_04 =?
?? ??? ?(case when column_13=0 then 0
?? ??? ? when column_13<90 then 1
?? ??? ? when column_13>=90 then 2
?? ??? ? end);

參考:http://blinkfox.com/postgresqlzhi-shi-zheng-li/

http://blog.csdn.net/sz_bdqn/article/details/8267691

?

轉載于:https://my.oschina.net/jrrx/blog/909571

總結

以上是生活随笔為你收集整理的Update语句:使用case when按条件批量更新的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。