gpt4 book ai didi

php - 选择起始数字,后跟 mysql 中的第一个单词

转载 作者:行者123 更新时间:2023-11-29 06:26:19 28 4
gpt4 key购买 nike

我的数据库中有很多地址。示例:1199 国道 218

我想选择起始数字,后跟第一个单词,并忽略地址的其余部分。所以我想通过调用这个来检索地址:1199 State

感谢您的帮助

最佳答案

如果您运行的是 MySQL 8.0,则可以使用 regexp_substr():

regexp_substr(mycolumn, '^\\d+\\s+\\w+')

正则表达式分割:

^    beginning of the string
\d+ a sequence of digits
\s+ a sequence of spaces
\w+ a sequence of word characters

Demo on DB Fiddle :

select regexp_substr('1199 State Route 218', '^\\d+\\s+\\w+') v
| v          || :--------- || 1199 State |

On the other hand, if you are just looking to filter the table with the beginning of the adress, then like should be enough:

select address from listing where address like '1199 State %'

请注意, clown 字符 (%) 前面有一个空格。这可确保您匹配整个第一个单词而不是其中的一部分。

关于php - 选择起始数字,后跟 mysql 中的第一个单词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59339745/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com