SQL通过在列中连接单词来获取结果

时间:2020-12-30 19:23:34

I have column store_name (varchar). In that column I have entries like prime sport, best buy... with a space. But when user typed concatenated string like primesport without space I need to show result prime sport. how can I achieve this? Please help me

我有列store_name (varchar)。在那篇专栏里,我有像prime sport, best buy……与空间。但当用户键入连接字符串,如primesport,而没有空格时,我需要显示结果primesport。我如何做到这一点?请帮我

3 个解决方案

#1


3  

SELECT *
FROM TABLE
WHERE replace(store_name, ' ', '') LIKE '%'+@SEARCH+'%' OR  STORE_NAME LIKE '%'+@SEARCH +'%'

#2


1  

Well, I don't have much idea, and even I am searching for it. But may be what I know works for you, You can achieve this by performing different type of string operations:

嗯,我没有太多的想法,甚至我也在寻找它。但我知道这可能对你有用,你可以通过执行不同类型的字符串操作来实现:

Mike can be Myke or Myce or Mikke or so on.
Cat an be Kat or katt or catt or so on.

For this you should write a function to generate number of possible strings and then form a SQL Query using all these, and query the database.

为此,您应该编写一个函数来生成可能的字符串数量,然后使用所有这些字符串组成一个SQL查询,并查询数据库。

A similar kind of search in known as Soundex Search from Oracle and Soundex Search from Microsoft. Have a look of it. this may work.

类似的搜索,如Oracle的Soundex search和Microsoft的Soundex search。看一看。这可能的工作。

And overall make use of functions like upper and lower.

整体上利用上下函数。

#3


1  

Have you tried using replace()

你试过用replace()吗?

You can replace the white space in the query then use like

您可以替换查询中的空格,然后使用like

SELECT * FROM table WHERE replace(store_name, ' ', '') LIKE '%primesport%'

从替换(store_name, ', ")如'%primesport%'的表中选择*

It will work for entries like 'prime soft' querying with 'primesoft'

它可以用于像'primesoft'和'primesoft'这样的查询

Or you can use regex.

也可以使用regex。

#1


3  

SELECT *
FROM TABLE
WHERE replace(store_name, ' ', '') LIKE '%'+@SEARCH+'%' OR  STORE_NAME LIKE '%'+@SEARCH +'%'

#2


1  

Well, I don't have much idea, and even I am searching for it. But may be what I know works for you, You can achieve this by performing different type of string operations:

嗯,我没有太多的想法,甚至我也在寻找它。但我知道这可能对你有用,你可以通过执行不同类型的字符串操作来实现:

Mike can be Myke or Myce or Mikke or so on.
Cat an be Kat or katt or catt or so on.

For this you should write a function to generate number of possible strings and then form a SQL Query using all these, and query the database.

为此,您应该编写一个函数来生成可能的字符串数量,然后使用所有这些字符串组成一个SQL查询,并查询数据库。

A similar kind of search in known as Soundex Search from Oracle and Soundex Search from Microsoft. Have a look of it. this may work.

类似的搜索,如Oracle的Soundex search和Microsoft的Soundex search。看一看。这可能的工作。

And overall make use of functions like upper and lower.

整体上利用上下函数。

#3


1  

Have you tried using replace()

你试过用replace()吗?

You can replace the white space in the query then use like

您可以替换查询中的空格,然后使用like

SELECT * FROM table WHERE replace(store_name, ' ', '') LIKE '%primesport%'

从替换(store_name, ', ")如'%primesport%'的表中选择*

It will work for entries like 'prime soft' querying with 'primesoft'

它可以用于像'primesoft'和'primesoft'这样的查询

Or you can use regex.

也可以使用regex。