问题来源: https://stackoverflow.com/questions/38567366/mapping-values-in-sql-select
有一个表格,就称它Plant,它有三列:id, name, category. 这是最简单的例子,所以不用担心通用性。
我想要返回的如下:
你可以使用Case表达式:
注:when后是查询到的值,then后是想要修改成为的值。
select
id,
name,
case
when category = 'fruits' then 'Fruit Plant'
when category = 'vegetables' then 'Vegetable Plant'
when category is null then 'unknown'
end as category
from Plant
原文:https://www.cnblogs.com/everfight/p/case_when.html