单列postgresql中的多规则替换
我正在尝试选择一列并进行多次替换,即单列postgresql中的多规则替换,postgresql,Postgresql,我正在尝试选择一列并进行多次替换,即 Col1 a b c d 选择col1并替换a=1、b=2和c=3 Col1 1 2 3 d 我知道更新和替换,但一次仅针对单个规则您可以使用以下用例: select case when col1 = 'a' then '1' when col1 = 'b' then '2' when col1 = 'c' then '3' else col1 end from table;
Col1
a
b
c
d
选择col1并替换a=1、b=2和c=3
Col1
1
2
3
d
我知道更新和替换,但一次仅针对单个规则您可以使用以下用例:
select
case when col1 = 'a' then '1'
when col1 = 'b' then '2'
when col1 = 'c' then '3'
else col1
end
from table;