有点笨拙,但您可以尝试使用正则表达式测试数字是否存在,然后使用子字符串获取第一个数字之前的所有内容
select newname, count(*)
from
(
select name,
case when name REGEXP '[0-9]' = 1 then
case
when locate('0',name) > 0 then substring(name,1,locate('0',name) -2)
when locate('1',name) > 0 then substring(name,1,locate('1',name) -2)
when locate('2',name) > 0 then substring(name,1,locate('2',name) -2)
when locate('3',name) > 0 then substring(name,1,locate('3',name) -2)
when locate('4',name) > 0 then substring(name,1,locate('4',name) -2)
when locate('5',name) > 0 then substring(name,1,locate('5',name) -2)
when locate('6',name) > 0 then substring(name,1,locate('6',name) -2)
when locate('7',name) > 0 then substring(name,1,locate('7',name) -2)
when locate('8',name) > 0 then substring(name,1,locate('8',name) -2)
when locate('9',name) > 0 then substring(name,1,locate('9',name) -2)
end
else name
end as newname
from t
) s
group by newname
;