简体   繁体   English

MySQL:选择列是给定字符串一部分的行

[英]MySQL: Select rows where a column is part of a given string

I search for a way to find a part of a given string in my table entries. 我在表项中寻找一种找到给定字符串一部分的方法。 The field is varchar in table. 该表中的字段为varchar。

Search for 搜索

/brands/brand/actona/kitchen-article/item/01945 /品牌/品牌/ actona /厨房文/项/ 01945

and want to find this row: 并想找到此行:

/brands/brand/actona/$

- or maybe this row -或者也许这一行

/brands/brand/actona/kitchen-$

Is there a way to solve this issue? 有办法解决这个问题吗? The problem is that the table have at least 57k entries. 问题在于该表至少具有57k条目。 I import the data from a old (too large) nginx-config file which are all permanent redirects. 我从旧的(太大)nginx-config文件中导入了数据,这些文件都是永久重定向。

Updated: What I need a roughly the opposite of "LIKE", because just a part of the string i search for is stored in table with a wildcard ($), that can match also another string that starts with the same. 更新:我需要大致上与“ LIKE”相反的内容,因为我搜索的字符串的一部分仅存储在带有通配符($)的表中,该字符串也可以匹配以该字符串开头的另一个字符串。 /brands/brand/actona/$ can match /brands/brand/actona/123 but also /brands/brand/actona/abc/def . /brands/brand/actona/$可以匹配/brands/brand/actona/123 ,也可以匹配/brands/brand/actona/abc/def

So when I search for /brands/brand/actona/abc/def or even /brands/brand/actona/abc/def/xyz it need to match the row /brands/brand/actona/$ 因此,当我搜索/brands/brand/actona/abc/def甚至是/brands/brand/actona/abc/def/xyz它需要匹配/brands/brand/actona/$

I actually try to outsource 57k permanent redirects from a nginx.config file to avoid checking a 6MB config file on each request. 我实际上尝试从nginx.config文件中外包57k永久重定向,以避免在每个请求中检查6MB的配置文件。

I'm so sorry for my terrible english :( 我很抱歉我的英语不好:(

Perhaps something like 也许像

SELECT * FROM TABLE
WHERE '/brands/brand/actona/kitchen-article/item/01945'
LIKE CONCAT('%', URLCOLUMN, '%');

How about something like this? 这样的事情怎么样?

SELECT * FROM table
WHERE
column REGEXP '(/[a-zA-Z0-9-]+)+\$?'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM