如何在MYSQL中查询反向部分匹配 [英] How to query reverse partial match in MYSQL

查看:87
本文介绍了如何在MYSQL中查询反向部分匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个搜索记录的查询,例如:

  SELECT  *  FROM   table   WHERE    LIKE  ' %value%'; 





它工作正常,但我想反向搜索也像:

  SELECT  *  FROM   table   WHERE  LIKE  ; 





这就像组合一样。

  SELECT  *  FROM   table   WHERE    LIKE  ' %value%'  LIKE  ; 





假设列的值类似于123456和i想要与0123456部分匹配。所以我需要一个查询来执行此操作:

  SELECT  *  FROM   table   WHERE    LIKE  ' %0123456%'   0123456   LIKE  ; 





所以wh at是这种查询的正确语法。

解决方案

检查这个

  SELECT  *  FROM   table   WHERE  charindex('  0123456')> 0  charindex('  0123456')> 0 





使用INSTR for MySQL,注意它的工作方式与charindex相反。



查看这个

mysql-instr-function [ ^ ]


假设SQL-Server。



这样的事情可能是:

  SELECT  * 
FROM table
WHERE column LIKE ' %' + @ Value + ' %'
@Value LIKE ' %' + + ' %'


I have a query for searching records like:

SELECT * FROM table WHERE column LIKE '%value%';



It's working fine but i want to put the reverse searching also like:

SELECT * FROM table WHERE value LIKE column;



Which becomes on combining like.

SELECT * FROM table WHERE column LIKE '%value%' OR value LIKE column;



Suppose column has a value like 123456 and i want to partially match it with 0123456. So i need a query to do this operation as:

SELECT * FROM table WHERE column LIKE '%0123456%' OR 0123456 LIKE column;



So what is the correct syntax for this kind of query.

解决方案

check this

SELECT * FROM table WHERE charindex(column,'0123456')>0 OR charindex('0123456',column)>0



Use INSTR for MySQL, Note It works in reverse order of charindex.

check this
mysql-instr-function[^]


Assuming SQL-Server.

Something like this maybe:

SELECT  *
FROM    table
WHERE   column LIKE '%' + @Value + '%'
    OR  @Value LIKE '%' + column + '%'


这篇关于如何在MYSQL中查询反向部分匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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