问题:将全名转换为大写首字母缩写。考虑下面的名字:

Stewie Griffin

要返回如下结果:

S.G.

 

解决方案:

select 
case when cnt=2 then 
trim(trailing '.' from 
concat_ws('.',
substr(substring_index(name,' ',1),1,1),
substr(name,
length(substring_index(name,' ',1))+2,1),
substr(substring_index(name,' ',-1),1,1),'.'))
else
trim(trailing '.' from
concat_ws('.',
substr(substring_index(name,' ',1),1,1),
substr(substring_index(name,' ',-1),1,1)
))
end as initials
from (
select name,length(name)-length(replace(name,' ','')) as cnt
from (
select replace('Stewie Grifin','.','') as name from t1
)y
)x;

相关文章:

  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-14
  • 2021-07-09
猜你喜欢
  • 2021-07-11
  • 2021-08-07
  • 2022-12-23
  • 2022-01-19
  • 2021-11-23
相关资源
相似解决方案