如何在MYSQL列中实现双向字符串搜索 [英] How to achieve Two way string search in column MYSQL

查看:75
本文介绍了如何在MYSQL列中实现双向字符串搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Everyone。

我写了一个查询来搜索下面的模式:

a:foobar b:foo



所以我想要的是:

Hello Everyone.
I have written a query to search for the pattern below:
a: foobar b: foo

So what I want is:

IF a Contains b OR b Contains a Then Return true.





我写的查询如下:



The Query I wrote is as below:

SELECT c1 FROM table WHERE 
INSTR(CAST(c2 as UNSIGNED),CAST(c3 as UNSIGNED))
OR
INSTR(CAST(c3 as UNSIGNED),CAST(c2 as UNSIGNED));





有没有更好的方法来实现这种双向搜索,以便INSTR不需要被提及两次?



Is there any better way to achieve this kind of two way search so that INSTR needs not to be mentioned twice?

推荐答案

尝试切换案例..

try Switch case..
select 
Case 
When (a=b or b=a) then 1 else 0 
End
from Table_Name



N:B-我不熟悉MySql:)

ref。

http://stackoverflow.com/questions/5282637/mysql-switch-case [ ^ ]


这篇关于如何在MYSQL列中实现双向字符串搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆