DQL
模糊查询通配符
符号 (-) 代表一个
例子: select*from Table_2 where name like’_’;
符号(%)赖子
例子:select*from Table_2 where name like ‘%白%’;
符号(【内容a,内容b】)字符集
例子:select*from 表名 where 列名 like ‘[孙,李]%’;
符号(【^内容c,内容d】)字符集取反
在介绍反向模糊查询之前先说一下,模糊查询:
SELECT * FROM table as t WHERE t.userName LIKE ‘%张三%’; (userName是table表的字段)
这个是一般的模糊查询的模板,而反向模糊查询的模板跟模糊查询的模板非常相似,只是相应的位置改变一下就行了。
反向模糊查询:
SELECT * FROM table as t WHERE “张三的偶像” LIKE t.userName; (查询的结果可以是:张三%,这个反向模糊结果是格式上的相同)。
范围查找
between…and
格式:列名 between 最小值 and 最大值
select * from goods where name like ‘%小米%’ and name like ‘%手机%’ and price between 1399 and 2000;
… and …
格式:列名>=最小值 and 列名<=最大值
例子:select * from goods where name like ‘%小米%’ and name like ‘%手机%’ and price >=1000 and price <= 2000;