简体   繁体   English

MySql 查询在字段中包含一个字符串

[英]MySql query contains a string in field

The question may be asked several times and I checked all of them but I can't get the answer.这个问题可能会被问几次,我检查了所有这些,但我无法得到答案。 I have a field named variables in my database 'test'.I have worked the query我的数据库“test”中有一个名为变量的字段。我已经完成了查询

select 'variables' from test WHERE variables LIKE '%{$ifIndex}%';

variables field contains comma seperated strings like ifIndex, IfType, IfStatus but I can't get it! variables 字段包含逗号分隔的字符串,如ifIndex, IfType, IfStatus但我无法得到它!

Try the following:请尝试以下操作:

select variables from test WHERE 'ifIndex' LIKE CONCAT('%',`variables` , '%') ;

if you're trying to match just the start:如果您只想匹配开始:

select variables from test WHERE 'ifIndex' LIKE CONCAT(`variables` , '%') 

当您将要查找的字符串仅使用 % 作为通配符放在任一侧时,这将实现您想要的结果。

select variables from test WHERE variables LIKE '%ifIndex%';

Try the following code试试下面的代码

select variables from test
WHERE variables LIKE '%{$ifIndex}%';

For field names don't put the single quotaition.对于字段名称,不要使用单个引号。

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

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