#案例1:查询哪个部门的员工个数>2
SELECT
COUNT(*),department_id
FROM
employees
GROUP BY
department_id
HAVING
COUNT(*)>2;
#:查询每个工种有奖金的员工的最高工资>12000的工种编号和最高工资
SELECT
MAX(salary),job_id
FROM
employees
WHERE
commission_pct IS NOT NULL
GROUP BY
job_id
HAVING
MAX(salary)>12000; #筛选12000放在分组后是因为,要等Max计算完再开始筛选
#查询领导编号>102的每个领导手下的员工的最低工资>5000的领导编号,以及其最底工资
SELECT
MIN(salary),manager_id
FROM
employees
WHERE
manager_id>102
GROUP BY
manager_id
HAVING MIN(salary)>5000;
原文:https://blog.51cto.com/14437184/2436639