如图
case when 一直以为常用的只有这样的形式
#1-----------------------------------
SELECT
epc.id,
case when epc.epc_type='1' then '1生鲜紧急变价'
when epc.epc_type='2' then '2海报纠错'
end as epc_type,
epc.form_flag,
epc.convenience_flag,
lst.cmmdty_code gds_cd,
lst.cmmdty_name,
**今天看到了另一种形式 **
#2-----------------------------------
SELECT
epc.id,
case when epc.epc_type='1' then '1生鲜紧急变价' else
case when epc.epc_type='2' then '2海报纠错' end end epc_type,
epc.form_flag,
epc.convenience_flag,
lst.cmmdty_code gds_cd,
lst.cmmdty_name,
有几个疑问
1、这两种写法是不是结果是一样的呢,有什么区别么??
2、什么时候才用第二种的写法
3、每个case when 语句在end后需要写别名,那么#2的写法因为有2个case,所以有2个end,但只写了一个别名。。
case when