语法:
select 分组函数,列(要求出现在group by的后面)
from 表
where ..
group by 分组的列表
order by ...
#案例:查询各个部门的平均工资
SELECT AVG(salary),department_id
FROM employees
GROUP BY
department_id
ORDER BY
department_id DESC;
#案例:查询每个工种的最高工资
SELECT
MAX(salary),job_id
FROM
employees
GROUP BY
job_id;
#案例:查询每个部门的位置个数
SELECT
COUNT(location_id),department_name
FROM
departments
GROUP BY
department_name;
#案例:查询邮箱中包含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 IS NOT NULL
GROUP BY
manager_id;