第四章:数据库条件查询和模糊查询

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_40667484/article/details/85012791

上一章:第三章:数据库查询基本操作


条件查询

where的用途(表条件)

有如下内容:
比较运算符(>,<,=)
逻辑运算符(and,or,not)
模糊查询
范围查询
排序(新添)

比较运算符(>,<,=)

代码:

select * from students where id<=2;

如图:检索id<=2的数据
在这里插入图片描述

逻辑运算符(and,or,not)

代码:

select * from students where not gender=1 and id>1;

如图:
在这里插入图片描述

模糊查询

利用下图所给的一些符号的用途来进行模糊查询
如图
在这里插入图片描述
%替换一个或者多个字符
_替换一个字符
^和*的用途

like,rlike的使用

(相当于where条件查询的=)

代码:

select * from students where name like "l%";//查询name字段中l开头的数据

如图:
在这里插入图片描述
代码:

select * from students where name like "___";//查询name字段中3个字符的数据

如图:
在这里插入图片描述

查询有2个字的名字

_ _和%使用举例

代码:

select * from students where name like "__%";

– 查询以l开始的姓名(rlike)

^和*使用举例

代码:

select * from students where name rlike "^l.*";

下一章:第五章:数据库范围查询和排序

猜你喜欢

转载自blog.csdn.net/qq_40667484/article/details/85012791