SQL语句case when 问题,急,求大神帮忙!
现有业务表某列数据如上表,先需使用sql语句筛选数据,让其带有“门诊”二字的列均显示“门诊”,带有“急诊”二字均显示“急诊”,SQL语句如下:
select
case when '%门诊' then '门诊' else '急诊' end clinic_label as a
from fact_clinic_master
用该语句查询,得到结果全是'急诊',请问是否不能这样用?? sql 数据
[解决办法]
select
case when clinic_label like '%门诊' then '门诊' else '急诊' end clinic_label as a
from fact_clinic_master
[解决办法]
select (case when clinic_label LIKE '%门诊' then '门诊' else '急诊' END)as a
from fact_clinic_master
--方法1,你的写法,稍微改一下就对了哈
select
case when clinic_label like'%门诊' then '门诊'
else '急诊' end as a
from fact_clinic_master
--方法2
select
case when charindex('门诊',clinic_label) >0 then '门诊'
else '急诊' end as a
from fact_clinic_master
select case when clinic_label LIKE '%门诊' then '门诊' else '急诊' END as a
from fact_clinic_master