sql中case when like %的使用

公司开发中遇见的一个问题,卡的种类的判断,如果卡的id中包含“CREDIT”则为信用卡,包含“DIBIT”则为借记卡,于是想到了使用case when的方式进行判断,由于有涉及到了包含匹配的问题,like %是首选,到网上搜了一下并经过实验证明case when like % 一块使用的正确性。

select
         fcb.id as id,
         fcb.status,
         c.CUSTOMERNUMBER as customernumber,
         c.FULLNAME as customerfullname,
         b.FULLNAME as bankname,
         f.DESCRIPTION as frpname,
         case when b.id like '%CREDIT' then '信用卡' when  b.id like '%DEBIT' then '借记卡' end as banktype
         from FastPayCustomerBranch fcb ,frp f ,bank b ,customer c                                
         where fcb.FRP_ID=f.ID and fcb.BANK_ID= b.ID and fcb.CUSTOMER_ID=c.id
规律如下:
Select  
     when column1 like '%包含内容%' then '结果1'  
     when column1 like '%包含内容%' then '结果2'  
     else '结果三' end as otherName,    
from table  
where 条件


你可能感兴趣的:(case,when,like,%)