在子查询中使用HAVING子句-SQL语言基础

时间:2024-05-15 13:25:01
【文件属性】:

文件名称:在子查询中使用HAVING子句-SQL语言基础

文件大小:5.26MB

文件格式:PPT

更新时间:2024-05-15 13:25:01

SQL 基础

在子查询中使用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);


网友评论