# 查询每个工种的最高工资 SELECT MAX(salary),job_id FROM `employees` GROUP BY `job_id`
# 查询每个位置上的部门个数 select count(*),`location_id` from `departments` group by `location_id`
# 添加筛选条件 # 查询邮箱中包含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`;
#①查询每个部门的员工个数 select count(*),`department_id` from `employees` group by `department_id`;
#②根据①的结果进行筛选,查询哪个部门的员工个数>2 select count(*),`department_id` from `employees` group by `department_id` having count(*)>2;
# 查询每个工种有奖金的员工的最高工资>12000的工种编号和最高工资 SELECT `job_id`,MAX(`salary`) FROM `employees` WHERE `commission_pct` IS NOT NULL GROUP BY `job_id` HAVING MAX(`salary`)>12000;
#查询领导编号>102的每个领导手下的员工的最低工资>5000的领导编号是哪个,以及其最低工资 SELECT `manager_id`,MIN(`salary`) FROM `employees` WHERE `manager_id`>102 GROUP BY `manager_id` HAVING MIN(`salary`)>5000;
select count(*),LENGTH(`last_name`) len_name from `employees` group by length(`last_name`) having COUNT(*)>5
#按多个字段分组 #查询每个部门每个工种的员工的平均工资 select avg(`salary`),department_id,job_id from `employees` group by `department_id`,`job_id`;
#查询每个部门每个工种的员工的平均工资,并且按平均工资的高低显示 SELECT AVG(`salary`),department_id,job_id FROM `employees` GROUP BY `department_id`,`job_id` ORDER BY AVG(`salary`) DESC;
#查询各job_id的员工工资的最大值,最小值,平均值,总和,并按job_id升序 select max(`salary`),min(`salary`),avg(`salary`),sum(`salary`),job_id from `employees` group by `job_id` order by job_id asc;
#查询员工最高工资和最低工资的差距<DIFFERENCE> select max(`salary`)-min(`salary`) DIFFERENCE from `employees`
#查询各个管理者手下员工的最低工资,其中最低工资不能低于6000,没有管理者的员工不计算在内 select min(`salary`) ,`manager_id` from `employees` where `manager_id` is not null group by `manager_id` having MIN(`salary`) >=6000
# 查询所有部门的编号,员工数虽和工资平均值,并按平均工资降序 select count(*),`department_id`,avg(`salary`) from `employees` group by department_id order by AVG(`salary`) desc
#选择具有名个job_id的员工人数 SELECT COUNT(*),`job_id` FROM `employees` GROUP BY `job_id`