当前位置:网站首页>mysql进阶(六)模糊查询的四种常见用法介绍
mysql进阶(六)模糊查询的四种常见用法介绍
2022-07-17 09:46:00 【InfoQ】
mysql
一、%
%%
SELECT * FROM [user] WHERE u_name LIKE '%三%';
SELECT * FROM [user] WHERE u_name LIKE '%三%' AND u_name LIKE '%猫%';
SELECT * FROM [user] WHERE u_name LIKE '%三%猫%'
二、_
SELECT * FROM [user] WHERE u_name LIKE '_三_';
SELECT * FROM [user] WHERE u_name LIKE '三__';
三、[ ]
SELECT * FROM [user] WHERE u_name LIKE '[张李王]三';
[ ]
SELECT * FROM [user] WHERE u_name LIKE '老[1-9]';
四、[^ ]
SELECT * FROM [user] WHERE u_name LIKE '[^张李王]三';
SELECT * FROM [user] WHERE u_name LIKE '老[^1-4]';
五、查询内容包含通配符处理
%
_
[
[ ]
function sqlencode(str)
str=replace(str,"';","';';")
str=replace(str,"[","[[]") ';
str=replace(str,"_","[_]")
str=replace(str,"%","[%]")
sqlencode=str
end function
六、拓展阅读 MySQL数据表中带OR的多条件查询
OR
OR
- 只要符合这几个查询条件的其中一个条件,这样的记录就会被查询出来。
- 如果不符合这些查询条件中的任何一条,这样的记录将被排除掉。
条件表达式1 OR 条件表达式2 [...OR 条件表达式n]
6.1 实例1
SELECT * FROM employee WHERE d_id=1001 OR sex LIKE '男';
6.2 实例2
SELECT * FROM employee WHERE
num IN(1,2,3) OR age BETWEEN 24 AND 26
OR homeaddress LIK '%厦门市%';
OR
AND
6.3 实例3
SELECT * FROM employee WHERE num IN(1,3,4) AND age=25 OR sex='女';
SELECT
SELECT * FROM employee WHERE sex='女' OR num IN(1,3,4) AND age=25;
SELECT
AND
OR
AND
OR
=
>
IN
BETWEEN AND
LIKE
LIKE
%
_
边栏推荐
- 小说里的编程 【连载之十五】元宇宙里月亮弯弯
- [troubleshooting] common problems and solutions when installing MySQL in Windows system
- 【Flink】Flink 设置检查点失败一次就报错 setTolerableCheckpointFailureNumber 不起作用
- Exchange array elements without creating temporary variables
- 06---光在介质中的特性
- Use < pre > and json Stringify handles the format of web page presentation JSON
- Development utility
- Dynamic memory management
- How long does software testing take?
- Left connection query of Android database
猜你喜欢
树状数组
Tree array
数据湖(二十):Flink兼容Iceberg目前不足和Iceberg与Hudi对比
案例分享 | 基于Linkis+DSS构建合合信息一站式数据开发平台
[Hongke] lidar safety system: making the world safer
Express
【微服务~高级】配置中心实战
Case sharing | build a one-stop data development platform for hehe information based on linkis+dss
静态路由!!静态路由!!静态路由!!
LabVIEW用了多线程,程序是不是会跑的更快些
随机推荐
【虹科】GenICam协议入门
C# - this 的用法
电脑拨号上网
QT串口通信
After working hard, I found that there were so many messes around
05---增透膜
TP5 wechat withdrawal merchants transfer to change (copying is available)
Set the ID field to increase automatically when creating tables in SQL Server (Navicat demo)
案例分享 | 基于Linkis+DSS构建合合信息一站式数据开发平台
【性能优化方法论系列】六、总结
Understanding of user / Account / Account
Data Lake (20): Flink is compatible with iceberg, which is currently insufficient, and iceberg is compared with Hudi
[paper notes] visual detection and capture method based on deep learning
QR decomposition for matrix inversion -- C engineering implementation
【微服务~高级】配置中心实战
分库分表
06---光在介质中的特性
Es conceptual model and basic faults
MySQL索引(三)
[Hongke] Introduction to genicam protocol