第三章带where条件的select语句_第1页
第三章带where条件的select语句_第2页
第三章带where条件的select语句_第3页
第三章带where条件的select语句_第4页
第三章带where条件的select语句_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、第三节 带where条件的select语句1. where条件语法:select字段1,字段2,字段3 from 表名 where 条件;2. 比较运算, = , = , = , 例:SQL select first_name,salary from employees where salary select * from student where sdept=计算机;3. 查询当前系统时间SQL select sysdate from dual; 其中sysdate为系统时间,dual为虚表题:查询员工表中,雇佣日期为1994-8-16的员工。SQL select * from emplo

2、yees where hire_date=16-8月 -94;题:查询员工表中,first_name为“Steven”的用户。SQL select * from employees where first_name=Steven;注意:1.在Oracle中,sql语句不区分大小写,但是,数据库中的记录内容是区分大小写的。2.日期类型的数据要用单引号表示,日期类型的格式必须与当前数据库的日期显示格式一致,也可以利用相应的函数转化(后面学)。4. betweenand查询记录中某一区域的数据,内容 SQL select first_name,salary from employees where

3、salary between 5000 and 10000;注意:其中between 条件1 and 条件2。其中 条件1 select first_name,salary from employees where salary not between 5000 and 10000;5. 范围内原则关键字:inSQL select first_name,salary from employees where salary in (17000,4200,12000);否定时,则为not in题:SQL select first_name from employees where employee

4、_id|first_name in (100Steven,202Pat);6.模糊查询like关键字,通配符:_ %通配符:_ 代表任意一个字符。通配符:% 代表任意多个字符。题:查询学生表中姓张的学生。SQL select * from student where sname like 张%;题:查询员工表中first_name以“E”开头的员工信息。SQL select * from employees where first_name like E%;题:查询员工表中,job_id以AD_开头的员工信息。SQL select first_name,job_id from employee

5、s where job_id like AD_%; -错误写法正确写法:SQL select first_name,job_id from employees where job_id like AD_% escape ;6. 判断是否为空利用 is null与is not nullSQL select first_name,commission_pct from employees where commission_pct is null;SQL select first_name,commission_pct from employees where commission_pct is n

6、ot null;7. 逻辑运算符(and , not , or)题:查询员工表中job_id为SA_MAN,工资大于8000的员工。SQL select job_id,salary from employees where job_id=SA_REP and salary8000;题:查询学生表中,计算机系的男生。SQL select * from student where sdept=计算机 and ssex=男;题:在计算机系中,年龄在12到22岁之间,姓张或姓李的男生。SQL select * from student where sdept=计算机 and sage=12 and s

7、age and or正确写法:SQL select * from student where sdept=计算机 and sage=12 and sage select first_name,salary from employees order by salary asc;-asc表示升序排列SQL select first_name,salary from employees order by salary desc;-desc表示降序排列默认不写asc和desc,则与asc一致为升序排列,如下:SQL select first_name,salary from employees order by salary; 题:查询学生表,先按性别升序排列,再按年龄降序排列SQL select * from student order by ssex,sage desc;注意:1.如果字段中含有null值,则此字段降序排在表的最上边;升序排在最下边。 2. order by 排序比较轻松,可以利用列名,列的位置,列的别名等排序。 3. 如果有过个字段进行排序,升序降序的字段要分别写上d

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论