简体   繁体   English

FIND_IN_SET用于Mysql中的一部分字符串

[英]FIND_IN_SET for part of string in Mysql

I need to make a query to a table in my database. 我需要查询数据库中的表。 Until now I was using FIND_IN_SET because I have strings like this: "twitter,bycicle,car" . 到目前为止,我一直使用FIND_IN_SET因为我有这样的字符串: “ twitter,bycicle,car”

Then, I could search by FIND_IN_SET("twitter", nameOfColumn) 然后,我可以通过FIND_IN_SET("twitter", nameOfColumn)

But now, I need to search just part of each "set", for example: "twitter>10,bycicle,car" 但是现在,我只需要搜索每个“集合”的一部分,例如: “ twitter> 10,bycicle,car”

It still works fine for bycicle and car but if I need to search for twitter, I cannot find it. 它对于自行车和汽车仍然可以正常工作,但是如果我需要搜索Twitter,就找不到它。 What is the correct way to do this? 正确的方法是什么?

The following query would give you what you want, however use it with caution with respect to the data you have: 以下查询将为您提供所需的信息,但是请谨慎使用有关您拥有的数据:

SELECT *
FROM table1
WHERE col1 RLIKE 'twitter'

Working Fiddle: http://sqlfiddle.com/#!2/66f538/1 工作小提琴: http ://sqlfiddle.com/#!2/66f538/1

Use LIKE operator: 使用LIKE运算子:

SELECT *
FROM table1
WHERE nameOfColumn LIKE '%twitter%';

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

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