Sql中CASE语法的常见案例
Sql中CASE语法的常见案例
案例1:
1 case when field1 is null then field2 2 else field2end as 'field'
案例2:可用于统计
1 case when field IS NOT NULL then 1 else 0 end as qty
案例3:
1 case WHEN STATUS='NEW' then '状态1' 2 WHEN STATUS IN ('feild1', 'feild2') then '状态2' 3 WHEN STATUS in ('feild3','feild4')then '状态3' 4 WHEN STATUS IN ('feild5' ,'feild6') then '状态4' 5 WHEN STATUS IN('feild7','feild8' )then '状态5' 6 WHEN STATUS IN ('feild12') then '状态9' 7 WHEN STATUS IN('feild9' )then '状态6' 8 WHEN STATUS IN('feild10' )then '状态7' 9 WHEN STATUS IN ('feild11') then '状态8' end AS STATUS,

浙公网安备 33010602011771号