- 1、本文档共18页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
Oracle Les06_子查询
子查询 目标 通过本章学习,您将可以: 描述子查询可以解决的问题 定义子查询。 列出子查询的类型。 书写单行子查询和多行字查询。 使用子查询解决问题 谁的工资比 Abel 高? 子查询语法 子查询 (内查询) 在主查询之前一次执行完成。 子查询的结果被主查询使用 (外查询)。 子查询 注意事项 子查询要包含在括号内。 将子查询放在比较条件的右侧。 除非进行Top-N 分析,否则不要在子查询中使用ORDER BY 子句。 单行操作符对应单行子查询,多行操作符对应多行子查询。 子查询类型 单行子查询 只返回一行。 使用单行比较操作符。 执行单行子查询 在子查询中使用组函数 子查询中的 HAVING 子句 首先执行子查询。 向主查询中的HAVING 子句返回结果。 非法使用子查询 子查询中的空值问题 多行子查询 返回多行。 使用多行比较操作符。 在多行子查询中使用 ANY 操作符 在多行子查询中使用 ALL 操作符 子查询中的空值问题 总结 通过本章学习,您已经学会: 在什么时候遇到什么问题应该使用子查询。 在查询是基于未知的值时应使用子查询。 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, 7000, 17000, 8300) and uses these results in its WHERE clause. The WHERE clause contains an equal (=) operator, a single-row comparison operator expecting only one value. The = operator cannot accept more than one value from the subquery and therefore generates the error. To correct this error, change the = operator to IN. Problems with Subqueries A common problem with subqueries is no rows being returned by the inner query. I
您可能关注的文档
- jeep手绘.doc
- JWJ-C2型柜式计轴设备说明书(V4.1)第七部分附录.doc
- JN15-12-31.5接地开关.doc
- Jordan标准形及其过渡矩阵的求法(姜天宇).doc
- K2导航_K2车载DVD导航_E路航导航_E路航专车专用导航.ppt
- KickStart实现无人值守安装Linux系统的操作记录.doc
- k1xzb笔记.doc
- KPI模块4.ppt
- KPT的用法.doc
- L195WA L2060WD不开机维修.doc
- 2024年度党员干部民主生活会班子对照检查材料.docx
- 公司党委领导班子2024年度民主生活会对照检查材料4个带头方面.docx
- 市府办(政府办)领导班子2024年民主生活会会后综合情况报告.docx
- 在2025年市司法局信息宣传工作推进会上的讲话.docx
- 在2025年全省文化旅游高质量发展推进会上的讲话.docx
- 在2025年全区工业、住建大规模设备更新推进会上的讲话.docx
- 党支部2024年组织生活会民主评议党员情况总结报告_1.docx
- 2024年度组织生活会个人对照检查剖析材料.docx
- 镇党委书记2024年度民主生活会对照检查材料1.docx
- 党支部2024年组织生活会民主评议党员情况总结报告.docx
文档评论(0)