zoukankan      html  css  js  c++  java
  • 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<>'信息系')

  • 相关阅读:
    SQL 索引
    SQL 存储
    C#编程中的66个好习惯,你有多少个?
    Delphi中如何让窗口最小化至系统托盘
    浅谈 堆和堆栈
    C#编程中的66个好习惯
    用ADO连接oracle的步骤
    如何卸载ocx包
    数据库中,Decimal数据类型
    [转载]内存区划分、内存分配、常量存储区、堆、栈、自由存储区、全局区
  • 原文地址:https://www.cnblogs.com/fuge/p/2342574.html
Copyright © 2011-2022 走看看