Several types in MySQL fuzzy query

_ Contains underscores: Usually means the number of characters used to limit the fuzzy query, except for the character to be queried, one underscore is to match a character, two underscores are two characters, n characters are to match n characters
--1.下划线开始 查询出来的结果就是含有两个字符并且是以学结尾的例如下面的这条语句
select name from tb_category where name LIKE "_学"
--查询结果如下:
--文学
--哲学
--国学
--2.下划线结尾 查询出来的结果就是含有两个字符并且是以学开头的例如下面的这条语句
select name from tb_category where name LIKE "学_"

--查询结果如下:
--学神
--学王
--学圣
--3.下划线开头和结尾 查询出来的结果就是含有三个字符并且是以学在中间的例如下面的这条语句
select name from tb_category where name LIKE "_学_"

--查询结果如下:
--爱学习
--大学师
--4.多个下划线查询出来的结果就是含有多个字符例如下面的这条语句是学后面两个下划线的
select name from tb_category where name LIKE "_学__"

--查询结果如下:
--大学老师
Contains% sign that matches 0 or more characters
--1.百分号%开头的查询出来的结果就是以查询字符结尾的任意个字符例如
select name from tb_category where name LIKE "%学"
--查询结果:
--文学
--心里学
--社会文学
--2.百分号%结尾的查询出来的结果就是以查询字符开头的任意个字符例如
select name from tb_category where name LIKE "学%"
--查询结果:
--学生文具
--学神
--3.双百分号%%的查询出来的结果就是包含查询字符的任意个字符例如
select name from tb_category where name LIKE "%学%"
--查询结果:
--学生文具
--国学
--英语学习与教学
Contains [] sign that matches any one of the characters in parentheses (this seems to be less useful after mysql8)
--例如以下就会匹配到括号中的单个字符
select all username from tab_info1 where username LIKE ' [张李]三'
--查询结果
-- 张三
-- 李三
The ^ sign indicates that any one of the matching characters is removed from the match (this seems to be less useful after mysql8)
--例如以下就会匹配到除去括号中的单个字符
select username from tab_info1 where username LIKE'飞[^0-2]';
--查询结果不包含飞0 飞1 飞2
Published 19 original articles · Like 7 · Visitor 6628

Guess you like

Origin blog.csdn.net/William_TWG/article/details/103549067