(数据库)09_分组函数------随堂练习

09_分组函数------随堂练习

练习一:

--查询各个管理者手下员工的最低工资,其中最低工资不能低于6000,
--没有管理者的员工不计算在内
select manager_id,min(salary)
from employees
where manager_id is not null
group by manager_id
having min(salary) >= 6000;

练习二:

--查询所有部门的名字,location_id,员工数量和工资平均值
select department_name,location_id,count(employee_id),avg(salary)
from employees e , departments d
where e.department_id(+) = d.department_id
group by department_name,location_id

练习三:
在这里插入图片描述

--查询公司在2001-2005年之间,每年雇用的人数,结果类似下面的格式
select count(*) total,
       count(decode(to_char(hire_date,'yyyy'),'2001',1,null)) "2001",
       count(decode(to_char(hire_date,'yyyy'),'2002',1,null)) "2002",
       count(decode(to_char(hire_date,'yyyy'),'2003',1,null)) "2003",
       count(decode(to_char(hire_date,'yyyy'),'2004',1,null)) "2004",
       count(decode(to_char(hire_date,'yyyy'),'2005',1,null)) "2005"
 from employees
where to_char(hire_date,'yyyy') in('2001','2002','2003','2004','2005');
发布了67 篇原创文章 · 获赞 6 · 访问量 1931

猜你喜欢

转载自blog.csdn.net/weixin_45801537/article/details/104270143