-
基础SQL语言中的分组结果排除
资源介绍
排除分组结果
*
每组中最多薪水大
于$2900的部门号”
EMP
DEPTNO SAL
------ --------
10 2450
10 5000
10 1300
20 800
20 1100
20 3000
20 3000
20 2975
30 1600
30 2850
30 1250
30 950
30 1500
30 1250
DEPTNO MAX(SAL)
------- --------
10 5000
20 3000
5000
3000
2850
*
Restricting Group Results
In the same way that you use the WHERE clause to restrict the rows that you select, you use the HAVING clause to restrict groups. To find the maximum salary of each department, but show only the departments that have a maximum salary of more than $2900, you need to do the following:
Find the average salary for each department by grouping by department number.
Restrict the groups to those departments with a maximum salary greater than $2900.