




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Restricting and Sorting Data ObjectivesAfter completing this lesson, you should be able to do the following:Limit the rows that are retrieved by a querySort the rows that are retrieved by a queryUse ampersand substitution to restrict and sort output at run timeLesson AgendaLimiting rows with:The WHE
2、RE clauseThe comparison conditions using =, =, BETWEEN, IN, LIKE, and NULL conditionsLogical conditions using AND, OR, and NOT operatorsRules of precedence for operators in an expressionSorting rows using the ORDER BY clauseSubstitution variablesDEFINE and VERIFY commandsLimiting Rows Using a Select
3、ion“retrieve allemployees in department 90”EMPLOYEESLimiting the Rows That Are SelectedRestrict the rows that are returned by using the WHERE clause:The WHERE clause follows the FROM clause.SELECT *|DISTINCT column|expression alias,.FROM tableWHERE condition(s);SELECT employee_id, last_name, job_id,
4、 department_idFROM employeesWHERE department_id = 90 ;Using the WHERE ClauseSELECT last_name, job_id, department_idFROM employeesWHERE last_name = Whalen ;Character Strings and DatesCharacter strings and date values are enclosed with single quotation marks.Character values are case-sensitive and dat
5、e values are format-sensitive.The default date display format is DD-MON-RR.SELECT last_name FROM employeesWHERE hire_date = 17-FEB-96 ;注:题53Comparison OperatorsNot equal toBetween two values (inclusive)BETWEEN.AND.Match any of a list of values IN(set)Match a character pattern LIKEIs a null value IS
6、NULLLess thanLess than or equal to=Greater thanEqual to=MeaningOperatorSELECT last_name, salaryFROM employeesWHERE salary = 10000AND job_id LIKE %MAN% ;Using the AND OperatorAND requires both the component conditions to be true:SELECT employee_id, last_name, job_id, salaryFROM employeesWHERE salary
7、= 10000OR job_id LIKE %MAN% ;Using the OR OperatorOR requires either component condition to be true:SELECT last_name, job_idFROM employeesWHERE job_id NOT IN (IT_PROG, ST_CLERK, SA_REP) ;Using the NOT OperatorLesson AgendaLimiting rows with:The WHERE clauseThe comparison conditions using =, 15000;Ru
8、les of PrecedenceSELECT last_name, job_id, salaryFROM employeesWHERE (job_id = SA_REPOR job_id = AD_PRES)AND salary 15000;12注:题56、57、60、61Lesson AgendaLimiting rows with:The WHERE clauseThe comparison conditions using =, =, BETWEEN, IN, LIKE, and NULL operatorsLogical conditions using AND, OR, and N
9、OT operatorsRules of precedence for operators in an expressionSorting rows using the ORDER BY clauseSubstitution variablesDEFINE and VERIFY commandsUsing the ORDER BY ClauseSort the retrieved rows with the ORDER BY clause:ASC: Ascending order, defaultDESC: Descending orderThe ORDER BY clause comes l
10、ast in the SELECT statement:SELECT last_name, job_id, department_id, hire_dateFROM employeesORDER BY hire_date ;SortingSorting in descending order:Sorting by column alias:SELECT last_name, job_id, department_id, hire_dateFROM employeesORDER BY hire_date DESC ;1SELECT employee_id, last_name, salary*1
11、2 annsalFROM employeesORDER BY annsal ;2SortingSorting by using the columns numeric position:Sorting by multiple columns:SELECT last_name, job_id, department_id, hire_dateFROM employeesORDER BY 3;3SELECT last_name, department_id, salaryFROM employeesORDER BY department_id, salary DESC;4注:题63、64、65、
12、66、67、68、69Lesson AgendaLimiting rows with:The WHERE clauseThe comparison conditions using =, =, BETWEEN, IN, LIKE, and NULL operatorsLogical conditions using AND, OR, and NOT operatorsRules of precedence for operators in an expressionSorting rows using the ORDER BY clauseSubstitution variablesDEFIN
13、E and VERIFY commandsSubstitution Variables. salary = ? department_id = ? . last_name = ? .I want to query different values.Substitution VariablesUse substitution variables to:Temporarily store values with single-ampersand (&) and double-ampersand (&) substitutionUse substitution variables to supple
14、ment the following:WHERE conditionsORDER BY clausesColumn expressionsTable namesEntire SELECT statementsSELECT employee_id, last_name, salary, department_idFROM employeesWHERE employee_id = &employee_num ;Using the Single-Ampersand Substitution VariableUse a variable prefixed with an ampersand (&) t
15、o prompt the user for a value:Using the Single-Ampersand Substitution VariableSELECT last_name, department_id, salary*12FROM employeesWHERE job_id = &job_title ;Character and Date Values with Substitution VariablesUse single quotation marks for date and character values:Specifying Column Names, Expr
16、essions, and TextSELECT employee_id, last_name, job_id,&column_nameFROM employeesWHERE &conditionORDER BY &order_column ;SELECT employee_id, last_name, job_id, &column_nameFROM employeesORDER BY &column_name ;Using the Double-Ampersand Substitution VariableUse double ampersand (&) if you want to reu
17、se the variable value without prompting the user each time:Lesson AgendaLimiting rows with:The WHERE clauseThe comparison conditions using =, =IS NULL!=IS LIKEIN BETWEENIn this lesson, you should have learned how to:Use the WHERE clause to restrict rows of output:Use the comparison conditionsUse the
18、 BETWEEN, IN, LIKE, and NULL operatorsApply the logical AND, OR, and NOT operatorsUse the ORDER BY clause to sort rows of output:Use ampersand substitution to restrict and sort output at run timeSELECT *|DISTINCT column|expression alias,.FROM tableWHERE condition(s)ORDER BY column, expr, alias ASC|DESC ;SummaryPract
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 光电工程师证书考试精细规划试题及答案
- 干货投资合同协议
- 宝马车合同协议
- 家电公司出货合同协议
- u视听说2试题及答案
- 光电产品的创新设计理念试题及答案
- 全面解读卫生管理考试试题及答案
- 客户线上发货合同协议
- 孵化基地租赁协议书模板
- 实木饭桌出租合同协议
- 魏晋风度课件
- 【MOOC】英国小说-南京大学 中国大学慕课MOOC答案
- 【读后续写】2021年11月稽阳联考读后续写讲评:Saving the Daisies 名师课件-陈星可
- 国开(浙江)2024年秋《信息技术与信息管理》形考作业1-4答案
- 《中华人民共和国突发事件应对法》知识培训
- 《智能家居系统》课件
- 福建师范大学《聚合物表征与测试》2023-2024学年第一学期期末试卷
- 《国家中长期教育改革和发展规划纲要》-20211107172134
- 麻风分枝杆菌感染
- 落实《中小学德育工作指南》制定的实施方案(pdf版)
- 案例分析肥胖症课件
评论
0/150
提交评论