GROUP BY
分组函数
添加筛选条件
查询邮箱中包含a字符的,每个部门的平均工资
SELECT
avg(salary),
department_id
from
employees
where
email like('%a%')
group by
department_id;
分组前筛选:
例:
查询有奖金的每个领导手下员工的最高工资
#查询有奖金的每个领导手下员工的最高工资
SELECT
MAX( salary ),
manager_id
FROM
employees
WHERE
commission_pct
GROUP BY
manager_id;
分组后筛选
查询哪个部门的员工个数>2
SELECT
count(*),
department_id
FROM
employees
GROUP BY
department_id
HAVING
COUNT(*)>2;