What I am trying to do is have a string that will be searched in a database, to make it clear how I want it searched I will give an example.
(我想做的是在数据库中搜索一个字符串,以明确说明我希望如何搜索它,下面举一个例子。)
Take the string "foobar" the database should do a search LIKE %oobar return the top item, then f%obar return the top item, then fo%bar return the top item, then foo%ar return the top item ... fooba% return the top item, and then restart at the beginning returning the second to top item of each of the LIKE statements.(以字符串“ foobar”为例,数据库应该执行如下搜索:%oobar返回顶层项目,然后f%obar返回顶层项目,然后fo%bar返回顶层项目,然后foo%ar返回顶层项目... fooba %返回顶层项目,然后从头开始,返回每个LIKE语句的第二个到顶层项目。)
Essentially we are searching for LIKE %est_of_string moving the % one to the left each time, and then restarting until the limit has been made.(本质上,我们正在搜索LIKE%est_of_string,每次将%%左移一次,然后重新启动直到达到限制为止。)
SELECT * WHERE LIKE '%tring' ORDER BY column
SELECT * WHERE LIKE 's%ring' ORDER BY column
SELECT * WHERE LIKE 'st%ing' ORDER BY column
SELECT * WHERE LIKE 'str%ng' ORDER BY column
SELECT * WHERE LIKE 'stri%g' ORDER BY column
SELECT * WHERE LIKE 'strin%' ORDER BY column
... LIMIT 50
(SELECT * WHERE LIKE '%tring' ORDER BY column
SELECT * WHERE LIKE 's%ring' ORDER BY column
SELECT * WHERE LIKE 'st%ing' ORDER BY column
SELECT * WHERE LIKE 'str%ng' ORDER BY column
SELECT * WHERE LIKE 'stri%g' ORDER BY column
SELECT * WHERE LIKE 'strin%' ORDER BY column
SELECT * WHERE LIKE 'stri%g' ORDER BY column
SELECT * WHERE LIKE 'strin%' ORDER BY column
... LIMIT 50
)
You may use Python or JavaScript, but wanting to use only SQL.(您可能使用Python或JavaScript,但只想使用SQL。)
Many Thanks in advance.(提前谢谢了。)
EDIT I know SELECT TOP x would be an okay solution, but I don't know how I would have it go through and cycle the % through the string.
(编辑我知道SELECT TOP x是一个好的解决方案,但是我不知道如何将它遍历并在字符串中循环%。)
ask by SharpIncTechAndProgramming translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…