Home  >  Article  >  Computer Tutorials  >  Perform fuzzy matching SQL database queries

Perform fuzzy matching SQL database queries

PHPz
PHPzforward
2024-01-23 10:30:05938browse

Perform fuzzy matching SQL database queries

Sql Server 环境,如果环境不对, 自己参考思路去修改吧

select * into #temp1 from table1 where len(col1) > 5 and len(col2) > 5

select * into #temp_end from #temp1 where 1=3

Declare @i int,@ii int

Declare @uid int,@col1 varchar(255),@col2 varchar(255)

Declare Fetch_Query_Cursor cursor for select UID,col1,col2 from #temp1

Open Fetch_Query_Cursor

Fetch Next From Fetch_Query_Cursor into @uid,@col1,@col2

while @@Fetch_status = 0

begin

select @i = 1,@ii=0

while @i

begin

if charindex(substring(@col1,@i,1),@col2) > 0

select @ii = @ii 1

select @i = @i 1

end

If @ii >=5

Insert into #temp_end select * from #temp1 where Uid = @uid

Fetch Next From Fetch_Query_Cursor into @uid,@col1,@col2

end

Close Fetch_Query_Cursor

Deallocate Fetch_Query_Cursor

Select * from #temp_end

Drop table #temp1

Drop table #temp_end

c语言怎样实现对数字模糊查找

字符串模糊查询,主要是输入不完全的信息进行查找,即每次查找的是待查询的内容中是否含有输入的内容,如果有,则表e68a84e8a2ade79fa5e9819331333363376434示找到了。下面详细的说明下模糊查询的实现方法,代码如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

#include

#include

#include

int main(int argc, const char * argv[])

{

char str[] = "hello welcome to china\0"; //源字符串

printf("input a string:\n");

char str2[20]; //要查找的字符串

fgets(str2, 19, stdin);

char *res;

res = memchr(str, str2[0], strlen(str)); //根据要查找的字符串第一个字符,切割源字符串

if (res == NULL)

{

printf("find nothing...\n");

return 0;

}

int n;

while (1)

{

n = memcmp(res, str2, strlen(str2) - 1); //比较

if (n != 0)

{

if (strlen(res)

{

printf("find nothing...\n");

return 0;

}

else

{

//根据要查找的第一个字符继续切割

res = memchr(res 1, str2[0], strlen(res));

if (res == NULL)

{

printf("find nothing...\n");

return 0;

}

}

}

else

{ //如果n = 0,找到

printf("%s is found..\n", str2);

return 0;

}

}

}

SQL模糊查询语句怎么写啊

1、假设表名为product,商品名为name,简界为remark.则可如下写:select [name],[remark] from product name like '�%' or remark like '�%'.注:上面单引号的aa你表模糊查询输入的字符。

2、select * from (表名) where (搜索名称)like '%%' and id like '%(简介)%'

3、用 Like 子句。比如:Select * from [TableName] where [名称] Like '%SQL%' and [简介] like '%Software%'这就是查询 [名称]字段中包含 “SQL”、并且[简介]字段中包含 “Software” 的记录。

4、selet * from userwhere name like '%小%'order by id ascasc代表升序 desc代表降序。

Perform fuzzy matching SQL database queries

扩展资料:

模糊搜索的定义主要有两种观点。

一是系统允许被搜索信息和搜索提问之间存在一定的差异,这种差异就是“模糊”在搜索中的含义。例如,查找名字Smith时,就会找出与之相似的Smithe, Smythe, Smyth, Smitt等。

二是实质上的搜索系统自动进行的同义词搜索。同义词由系统的管理界面配置。例如,配置“计算机”与“computer”为同义词后,搜索“计算机”,则包含“computer”的网页也会出现在搜索结果中。

将本地图片输入到图片搜索框,

1、假如你的图片带有意义的标题,比如“衣服”,那么搜索结果会显示相关文本搜索结果

2、假如你的图片标题没有任何含义,搜索结果只显示相关图片。

3、搜索精准度随不同图片可达到的满意程度不同,往往越是主流商业图片越精准

目前像、谷歌等搜索引擎及淘宝等平台均可实现此应用。

Text fuzzy search

Search engine or portal website search: Enter text into the search box and select fuzzy search mode to get matching results.

Database search: The general fuzzy query statement is as follows: SELECT field FROM table WHERE certain field Like condition.

Regarding conditions, SQL provides four matching modes:

1, %: represents any 0 or more characters. Can match characters of any type and length. In some cases, if it is Chinese, please use two percent signs (%%) to express it.

2, _: represents any single character. Matches a single arbitrary character, which is often used to limit the character length of expressions:

3. [ ]: Indicates one of the characters listed in brackets (similar to a regular expression). Specify a character, string, or range to match any of them.

4, [^ ]: Indicates a single character not listed in brackets. Its value is the same as [], but it must match any character other than the specified character.

5, when the query content contains wildcard characters

Due to wildcards, our query statements for special characters "%", "_", and "[" cannot be implemented normally. However, the special characters can be queried normally if they are enclosed in "[ ]".

In different databases, the fuzzy search statements will be different, which can be learned in the system help document.

Reference source: Sogou Encyclopedia: Fuzzy Search

The above is the detailed content of Perform fuzzy matching SQL database queries. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:docexcel.net. If there is any infringement, please contact admin@php.cn delete