如何在一列中找到字符串的首字母缩写?

huangapple go评论57阅读模式
英文:

How to find string Initials in a column?

问题

select * from table where COL_2 regexp '\\b[A-Z]\\.( [A-Z]\\.)?\\b';
英文:

Let's say I have the following table:

COL_1 COL_2
1 J. Z.
2 T. M. Z.
3 Banana. Jacobs
4 I.
5 Busta Rhymes.
6 Jesus H. Christ

How would I find strings that contain strings that contain initials of the format below:

  • A.
  • A. B.
  • A. B. C.

I tried using like '%[A-Z.]%', but it returns me all of the strings that contain a dot. For example:

select * from table where COL_2 like '%[A-Z].%'

答案1

得分: 2

你可以将空格连接到要搜索的列中,并将空格包含在搜索参数中:

select * 
from table 
where concat(' ', COL_2, ' ') like '% [A-Z]. %';
英文:

You could concatenate spaces to the searched column and include spaces in the search argument:

select * 
from table 
where concat(' ', COL_2, ' ') like '% [A-Z]. %';

huangapple
  • 本文由 发表于 2023年2月10日 04:21:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75404027.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定