登录 注册
当前位置:主页 > 资源下载 > 在SQL语言基础中,学习如何在子查询中运用HAVING子句

在SQL语言基础中,学习如何在子查询中运用HAVING子句

  • 更新:2024-07-07 11:58:32
  • 大小:5.26MB
  • 推荐:★★★★★
  • 来源:网友上传分享
  • 类别:Informix - 数据库
  • 格式:PPT

资源介绍

在子查询中使用HAVING子句 * SQL> SELECT deptno, MIN(sal) 2 FROM emp 3 GROUP BY deptno 4 HAVING MIN(sal) > 5 (SELECT MIN(sal) 6 FROM emp 7 WHERE deptno = 20); Oracle服务器首先执行子查询. Oracle服务器将结果返回给主查询的HAVING子句. 800 * SELECT deptno, MIN(sal) FROM emp GROUP BY deptno HAVING MIN(sal) > (SELECT MIN(sal) FROM emp WHERE deptno = 20); 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 20. Example Find the job with the lowest average salary. DEPTNO MIN(SAL) --------- --------- 10 1300 30 950 SQL> SELECT job, AVG(sal) 2 FROM emp 3 GROUP BY job 4 HAVING AVG(sal) = (SELECT MIN(AVG(sal)) 5 FROM EMP 6 GROUP BY job);