case then与函数结合使用

现象:
case then与函数结合使用

方法:
1:case与len()函数使用
这里写图片描述
2:case多条件与like使用
这里写图片描述

(1)
select top 5
            case when len(ISNULL(max(factory),'未知')) > 20 then SUBSTRING(ISNULL(max(factory),'未知'),1,20)+'...' 
            else ISNULL(max(factory),'未知')  end as name,
<!--            SUBSTRING(ISNULL(max(factory),'未知'),1,20) as name, -->
            SUM(ranking) as ranking
        from 
            cid 
        where year='2017'
        group by factory
        order by ranking desc2case when goodclass like '%鸡%' then '鸡'
        when  goodclass like '%猪%' then '猪'
        when  goodclass like '%牛%' then '牛'
        when  goodclass like '%羊%' then '羊'
        else   '其他'  end 
        as goodsClass

猜你喜欢

转载自blog.csdn.net/hcwbr123/article/details/79472850