现象:
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 desc
(2)
case when goodclass like '%鸡%' then '鸡'
when goodclass like '%猪%' then '猪'
when goodclass like '%牛%' then '牛'
when goodclass like '%羊%' then '羊'
else '其他' end
as goodsClass