SQL查询(二)--case when 的使用
TALK IS CHEAP. SHOW ME THE CODE.
case when的使用
根据case when 条件新建一列
Select 字段1,字段2,
(case when condition1 then a
when condition2 then b
else c end) as 分类
from table
根据case when 条件新建多列
Select 字段1,字段2,
(case when condition1 then a else b end) as 字段3,
(case when condition2 then c else b end) as 字段4
From table
总结:简单case函数,更多的是对本列自身的判断与处理;而case搜索函数,是一种if-else的条件判断。