Oracle公司内部数据库培训资料02_过滤和排序数据

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

Copyright©OracleCorporation,2001.Allrightsreserved.过滤和排序数据2-2Copyright©OracleCorporation,2001.Allrightsreserved.目标通过本章学习,您将可以:•在查询中过滤行。•在查询中对行进行排序。2-3Copyright©OracleCorporation,2001.Allrightsreserved.在查询中过滤行返回在90好部门工作的所有员工的信息EMPLOYEES…2-4Copyright©OracleCorporation,2001.Allrightsreserved.过滤•使用WHERE子句,将不满足条件的行过滤掉。•WHERE子句紧随FROM子句。SELECT*|{[DISTINCT]column|expression[alias],...}FROMtable[WHEREcondition(s)];2-5Copyright©OracleCorporation,2001.Allrightsreserved.WHERE子句SELECTemployee_id,last_name,job_id,department_idFROMemployeesWHEREdepartment_id=90;2-6Copyright©OracleCorporation,2001.Allrightsreserved.字符和日期•字符和日期要包含在单引号中。•字符大小写敏感,日期格式敏感。•默认的日期格式是DD-MON-RR。SELECTlast_name,job_id,department_idFROMemployeesWHERElast_name='Whalen';2-7Copyright©OracleCorporation,2001.Allrightsreserved.比较运算操作符===含义等于大于大于、等于小于小于、等于不等于2-8Copyright©OracleCorporation,2001.Allrightsreserved.SELECTlast_name,salaryFROMemployeesWHEREsalary=3000;比较运算2-9Copyright©OracleCorporation,2001.Allrightsreserved.其它比较运算操作符BETWEEN...AND...IN(set)LIKEISNULL含义在两个值之间(包含边界)等于值列表中的一个模糊查询空值2-10Copyright©OracleCorporation,2001.Allrightsreserved.BETWEEN使用BETWEEN运算来显示在一个区间内的值。SELECTlast_name,salaryFROMemployeesWHEREsalaryBETWEEN2500AND3500;LowerlimitUpperlimit2-11Copyright©OracleCorporation,2001.Allrightsreserved.SELECTemployee_id,last_name,salary,manager_idFROMemployeesWHEREmanager_idIN(100,101,201);IN使用IN运算显示列表中的值。2-12Copyright©OracleCorporation,2001.Allrightsreserved.LIKE•使用LIKE运算选择类似的值•选择条件可以包含字符或数字:–%代表一个或多个字符。–_代表一个字符。SELECTfirst_nameFROMemployeesWHEREfirst_nameLIKE'S%';2-13Copyright©OracleCorporation,2001.Allrightsreserved.•‘%’和‘-’可以同时使用。•可以使用ESCAPE标识符选择‘%’和‘_’符号。LIKESELECTlast_nameFROMemployeesWHERElast_nameLIKE'_o%';2-14Copyright©OracleCorporation,2001.Allrightsreserved.NULL使用NULL判断空值。SELECTlast_name,manager_idFROMemployeesWHEREmanager_idISNULL;2-15Copyright©OracleCorporation,2001.Allrightsreserved.逻辑运算操作符ANDORNOT含义逻辑并逻辑或逻辑否2-16Copyright©OracleCorporation,2001.Allrightsreserved.ANDAND要求和的关系为真。SELECTemployee_id,last_name,job_id,salaryFROMemployeesWHEREsalary=10000ANDjob_idLIKE'%MAN%';2-17Copyright©OracleCorporation,2001.Allrightsreserved.OROR要求或关系为真。SELECTemployee_id,last_name,job_id,salaryFROMemployeesWHEREsalary=10000ORjob_idLIKE'%MAN%';2-18Copyright©OracleCorporation,2001.Allrightsreserved.SELECTlast_name,job_idFROMemployeesWHEREjob_idNOTIN('IT_PROG','ST_CLERK','SA_REP');NOT2-19Copyright©OracleCorporation,2001.Allrightsreserved.优先级可以使用括号改变优先级顺序优先级1算术运算符2连接符3比较符4IS[NOT]NULL,LIKE,[NOT]IN5[NOT]BETWEEN6NOT7AND8OR2-20Copyright©OracleCorporation,2001.Allrightsreserved.SELECTlast_name,job_id,salaryFROMemployeesWHEREjob_id='SA_REP'ORjob_id='AD_PRES'ANDsalary15000;优先级2-21Copyright©OracleCorporation,2001.Allrightsreserved.SELECTlast_name,job_id,salaryFROMemployeesWHERE(job_id='SA_REP'ORjob_id='AD_PRES')ANDsalary15000;优先级使用括号控制执行顺序。2-22Copyright©OracleCorporation,2001.Allrightsreserved.SELECTlast_name,job_id,department_id,hire_dateFROMemployeesORDERBYhire_date;ORDERBY子句•使用ORDERBY子句排序–ASC:升序–DESC:降序•ORDERBY子句在SELECT语句的结尾。…2-23Copyright©OracleCorporation,2001.Allrightsreserved.降序排序SELECTlast_name,job_id,department_id,hire_dateFROMemployeesORDERBYhire_dateDESC;…2-24Copyright©OracleCorporation,2001.Allrightsreserved.按别名排序SELECTemployee_id,last_name,salary*12annsalFROMemployeesORDERBYannsal;…2-25Copyright©OracleCorporation,2001.Allrightsreserved.•按照ORDERBY列表的顺序排序。•可以使用不在SELECT列表中的列排序。SELECTlast_name,department_id,salaryFROMemployeesORDERBYdepartment_id,salaryDESC;多个列排序…2-26Copyright©OracleCorporation,2001.Allrightsreserved.总结SELECT*|{[DISTINCT]column|expression[alias],...}FROMtable[WHEREcondition(s)][ORDERBY{column,expr,alias}[ASC|DESC]];通过本课,您应该可以完成:•使用WHERE子句过滤数据–使用比较运算–使用BETWEEN,IN,LIKE和NULL运算–使用逻辑运算符AND,OR和NOT•使用ORDERBY子句进行排序。2-27Copyright©OracleCorporation,2001.Allrightsreserved.

1 / 27
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功