SQL(三)——where子句

常用的查询条件
在这里插入图片描述

比较

“=”、“<”、“>”、“<=”、“>=”、“!=”、“!>”、“!<”、“not + 运算符”

select distinct sname
from student
where sdept='cs'

多重条件

“and”、“or”、“not”

select distinct sname
from student
where sage>20 and sdept='cs'

确定范围

“between and”、“not between and”,范围是闭区间

select distinct sname, sage
from student
where sage between 20 and 21

确定集合

“in()”、“not in()”
用 “in()” 可以用来查找属性值属于指定集合的元组

select distinct sname, sage
from student
where sdept in('cs','is')

字符匹配

通配符“%”

“%”可匹配任意长度的字符串

select distinct sname, sage
from student
where sname like '爱%青菜'

通配符“_”

“_”代表任意单个字符

select distinct sname, sage
from student
where sname like '王_'

在这里插入图片描述

转义字符“\”

这是MySQL的写法,和java转义一样

select distinct sname, sage, sdept
from student
where sdept like 'cs\_%'

在这里插入图片描述

空值查询

“is null”、“is not null”

select distinct sname, sage, sdept
from student
where sage is null
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值