分组查询--小结练习

1. 查询个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;
2. 查询员工最高工资和最低工资的差距

select max(salary)-min(salary) difference from employees;
3. 查询各个管理者手下的员工的最低工资,其中最低工资不能低于6000,没有管理者的员工不计算在内

select  min(salary),manager_id
from employees
where manager_id is not null
group by manager_id
having min(salary)>=6000;
4. 查询所有的部门编号,员工数量和工资平均值,并按平均公司降序

select department_id, count(*),avg(salary) avg
from employees
group by department_id
order by avg desc;
5. 选择各个job_id 的员工个数

select count(*),job_id
from employees
group by job_id;

 

上一篇:C Primer Plus 第6版 第二章编程练习


下一篇:【硬刚ES】ES基础(三十八)Pipeline 聚合分析