英文:
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]. %';
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论