现在我有以下查询:
SELECT "type" AS "modifiedType"
FROM "Table"
WHERE "type" = 'type1' OR "type" = 'type2'
我想要的是像这样返回 modifiedType
:
if "type" = 'type1' then 'modifiedType1'
else if "type" = 'type2' then 'modifiedType2'
所以我只想在原始列值的基础上用另一个值修改列值。
在 ENUM
中输入列而不是字符串。
我正在使用 Postgres 9.3(或 9.4?)。
最佳答案
使用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')
顺便说一句:type
不是一个好的列名
关于sql - 如何根据此列将 SELECT 输出列转换为任意值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24609773/