MySQL02-(where子句)

where子句对进行筛选

后面可跟 算术表达式(+ - * /)、关系表达式(<>=)、逻辑表达式(not、and、or)

  • 关系运算符
select*from sc where 成绩>60
select 姓名,性别,班级 from student  where left(姓名,l)=‘赵’
select  姓名,性别,班级  from  student  where year(出生日期)>1990
select Sname  from student  where  sdept!=‘cs’
select distinct  sno  from  sc  where grade<60
  • 逻辑运算符
select * from sc where not 成绩>=60
    #使用逻辑运算符not
        #not:返回不满足表达式的行
select * from student where 班级=4and 性别=‘男’
    #使用逻辑运算符and
select * from course  where 考试类型=‘机考’or 学分=3
    #使用逻辑运算符or
  • 范围运算符
select sname,sdept,sage  from student where sage between 20 and  23
select sname,sdept,sage  from student where sage not between 20 and  23
  • 列表运算符
select sname,ssex  from  student  where sdept in('is','ma','cs')
   # 使用列表运算符in
select sname,ssex  from  student  where sdept not in('is','ma','cs')
    #使用列表运算符not in
  • 模糊匹配运算符
select 字段 fromwhere 某字段  like  条件
表达含义示例
[not] like +%%表示任意0个或多个字符,可匹配任意类型和长度的字符select sname,sno,ssex from student where sname like ‘刘%’
[not] like +“_”_:表示任意单个字符。它常用来限制表达式的字符长度select sname from student where sname like ‘_小刚’
[not] like +[ ][ ]:指定范围或集合内的任何单个字符。例如:[a-f],[abcdef],要求所匹配对象为他们中任一个select * from persons where city like '[aln]%'查询居住的城市以“A”或“L”或“N”开头的
[not] like + [^][^]:表示不在括号所列之内的单个字符。其取值和[ ]相同,但它要求所匹配对象为指定字符以外的任一个字符。select * from user where name like ‘[^张李王]三’ 将找出不姓“张”、“李”、“王”的“赵三”、“孙三”等
  • 空值运算符
select sno,cno from sc where  grade  is null
条件表达式可使用多重条件查询

逻辑运算符:and 和 or 来联结多个查询条件

  1. and的优先级高于or
  2. 但可以用括号改变优先级
select sname from student where sdept=‘cs’and sage<20
select sname,SSex from student where sdept='is' or sdept='ma' or sdept='cs'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值