注意: 查询列表必须特殊,要求分组函数和group by后出现的字段
引入:查询每个部门的平均工资 SELECT AVG(salary) FROM employees;
案例1;查询每个工种的最高工资 SELECT MAX(salary),job_id FROM employees GROUP BY job_id;
案例2:查询每个部门个数 SELECT COUNT(*),location_id FROM departments GROUP BY location_id
添加筛选条件 案例1:查询邮箱中包含a字符的,每个部门的平均工资 SELECT AVG(salary),department_id FROM employees WHERE email LIKE '%a%' GROUP BY department_id;
案例2:查询有奖金的每个领导手下员工的最高工资 SELECT MAX(salary),manager_id FROM employees WHERE commission_pct IS NOT NULL GROUP BY manager_id;