现在我有以下查询:
SELECT "type" AS "modifiedType"
FROM "Table"
WHERE "type" = 'type1' OR "type" = 'type2'
Run Code Online (Sandbox Code Playgroud)
modifiedType我想要的是这样返回:
if "type" = 'type1' then 'modifiedType1'
else if "type" = 'type2' then 'modifiedType2'
Run Code Online (Sandbox Code Playgroud)
所以我只想根据原始列值用另一个值修改列值。ENUM在非字符串中键入列。
我正在使用 Postgres 9.3(或 9.4?)。
小智 5
使用一个CASE声明:
select type,
case
when type = 'type1' then 'modifiedType1'
when type = 'type2' then 'modifiedType2'
else type
end as modifiedType
from the_table
WHERE type in ('type1', 'type2')
Run Code Online (Sandbox Code Playgroud)
顺便说一句:type这对于专栏来说不是一个好名字