-
在SQL语言基础中,学习如何在子查询中运用HAVING子句
资源介绍
在子查询中使用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);
- 上一篇: mongodb-linux-x86_64-3.4.6
- 下一篇: Robo3T1.1.1