示例场景:
(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