- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
子查询 目标 通过本章学习,您将可以: 描述子查询可以解决的问题 定义子查询。 列句子查询的类型。 书写单行子查询和多行字查询。 使用子查询解决问题 谁的工资比 Abel 高? 子查询语法 子查询 (内查询) 在主查询之前一次执行完成。 子查询的结果被主查询使用 (外查询)。 子查询 注意事项 子查询要包含在括号内。 将子查询放在比较条件的右侧。 除非进行Top-N 分析,否则不要在子查询中使用ORDER BY 子句。 单行操作符对应单行子查询,多行操作符对应多行子查询。 子查询类型 单行子查询 只返回一行。 使用单行比较操作符。 执行单行子查询 在子查询中使用组函数 子查询中的 HAVING 子句 首先执行子查询。 向主查询中的HAVING 子句返回结果。 非法使用子查询 子查询中的空值问题 多行子查询 返回多行。 使用多行比较操作符。 在多行子查询中使用 ANY 操作符 在多行子查询中使用 ALL 操作符 子查询中的空值问题 总结 通过本章学习,您已经学会: 在什么时候遇到什么问题应该使用子查询。 在查询是基于未知的值时应使用子查询。 Using Group Functions in a Subquery You can display data from a main query by using a group function in a subquery to return a single row. The subquery is in parentheses and is placed after the comparison condition. The example on the slide displays the employee last name, job ID, and salary of all employees whose salary is equal to the minimum salary. The MIN group function returns a single value (2500) to the outer query. The HAVING Clause with Subqueries You can use subqueries not only in the WHERE clause, but also in the HAVING clause. The Oracle server executes the subquery, and the results are returned into the HAVING clause of the main query. The SQL statement on the slide displays all the departments that have a minimum salary greater than that of department 50. Example Find the job with the lowest average salary. SELECT job_id, AVG(salary) FROM employees GROUP BY job_id HAVING AVG(salary) = (SELECT MIN(AVG(salary)) FROM employees GROUP BY job_id); … Errors with Subqueries One common error with subqueries is more than one row returned for a single-row subquery. In the SQL statement on the slide, the subquery contains a GROUP BY clause, which implies that the subquery will return multiple rows, one for each group it finds. In this case, the result of the subquery will be 4400, 6000, 2500, 4200, 7000, 17000, and 8300. The outer query takes the results of the subquery (4400, 6000, 2500, 4200
您可能关注的文档
最近下载
- 《国家机关的产生》课件.pptx VIP
- 成都理工大学,成考,期末考试复习资料,电子商务技术(专升本).doc VIP
- 石油工程事故案例分享(课堂PPT).ppt VIP
- 成都理工大学,成考,期末考试复习资料JAVA语言及面向对象程序设计(专升本).doc VIP
- 成都理工大学,成考,期末考试复习资料,J2EE框架与程序设计(专升本).doc VIP
- 区域电力网设计.docx VIP
- 2025中国纺织行业产品数字护照(DPP)白皮书.pdf
- 2025产品数字护照(DPP)技术发展报告.docx
- Roland罗兰TD-50X中文参考手册.pdf
- 霍林郭勒市生源报废汽车回收拆解有限公司报废汽车拆解变更项目环境影响评价文件(报告表).doc VIP
原创力文档


文档评论(0)