where查询条件的指定,between and,in,like

某些查询条件
确定范围between and,not between and
确定集合in,not in
字符匹配like,not like
空值is null,is not null
多重条件and,or,not

1。确定范围

     查询年龄在(不在)21到24之间的学生姓名,年龄。

   select sn,age from s where age between 21 and 24  (select sn,age from s where age not between 21 and 24)

2.确定集合

   查询是(不是)信息系、自动化系和计算机系的学生的姓名

   select sn from s where dept in ('信息系',‘自动化系’,‘计算机系’)  ( select sn from s where dept not in ('信息系',‘自动化系’,‘计算机系’)) 

  in谓词实际上是多个or运算符的缩写

3.字符匹配

   查询名字中第二个字为“阳”字的学生的姓名。

   select sn  from where sn like '_阳%'     查询结果 :季阳,季阳春,季阳春春

  换码字符 :escape 对通配符(%,_,[],[^])进行转义

  查询d_n课程的课程名和学分

select cno,ct from c where cn like ‘d\_n’ escape '\'

escape'\'短语表示“\“为换码字符,这样匹配串中紧跟在\后面的字符”_“不再具有通配符的含义,而是取其本身字符含义,即被转义为普通的”_“字符

4.空值的查询

查询所有有(缺少)成绩的学生的学号和相应的课程号

select sno,cno from sc where score is not null  (select sno,cno from sc where score is  null)

5.多重条件查询

 and、or、not可连接多个查询条件。优先级:not>and>or。可用括号改变运算的优先顺序。

查询计算机系年龄21以下的学生姓名。

select sn from where dept='计算机系' and age<21

  查询信息系、自动化系和计算机系的学生的姓名

select sn,sex from where dept='计算机系' or dept='自动化系' or dept='信息系'

select sn,sex from where not (dept <>'计算机系' and dept<>'自动化系' and dept<>'信息系')

转载于:https://www.cnblogs.com/fuge/archive/2011/12/28/2342574.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值