一个列里面的不同内容,怎么计算个数,不同内容有些不同名字但可能是一个类型,比如,一个列里有小车,自行车,摩托车,电动车,三轮车,船,大船,小船……这列中,算车类的个数和船类个数,这种的sql怎么写
select case
when 类型 in ('小车', '自行车', .. .) then
'车类'
when 类型 in ('小船', '船', .. .) then
'船类'
else
'其他'
end as 类型,
count(1) as 数量
from .. .
group by case
end
如果用关键字
case when 字段 like '%车%'
then '车类'
when 字段 like '%船%'
then '船类'
else '其他' end as '类型'