分组函数
select max(salary) Maximum, min(salary) Minimum, round(sum(salary)) Sum, round(avg(salary)) Average
from employees;
select max(salary) Maximum, min(salary) Minimum, round(sum(salary)) Sum, round(avg(salary)) Average
from employees group by job_id;
select job_id, count(employee_id) from employees group by job_id;
select count(distinct MANAGER_id) "Number of Managers" from EMPLOYEES;
select max(salary) - min(salary) DIFFERENCE from employees;
select MANAGER_ID, min(SALARY)
from (select * from EMPLOYEES where MANAGER_ID is not null)
group by MANAGER_ID having min(SALARY) > 6000
order by min(SALARY) desc;
select DEP.DEPARTMENT_NAME, DEP.LOCATION_ID, count(EMP.EMPLOYEE_id), round(avg(EMP.SALARY), 2)
from EMPLOYEES EMP, DEPARTMENTS DEP
where EMP.DEPARTMENT_ID = DEP.DEPARTMENT_ID
group by DEP.DEPARTMENT_NAME, DEP.LOCATION_ID;
select count(*) total,
sum(decode(to_char(hire_date,'yyyy'),'2000',1,0))"2000" ,
sum(decode(to_char(hire_date,'yyyy'),'2001',1,0))"2001",
sum(decode(to_char(hire_date,'yyyy'),'2002',1,0))"2002",
sum(decode(to_char(hire_date,'yyyy'),'2003',1,0))"2003"
from employees e;
select job_id ,sum(emp.salary) total,
sum(decode(emp.department_id,20,1,0))"20",
sum(decode(emp.department_id,50,1,0))"50",
sum(decode(emp.department_id,80,1,0))"80",
sum(decode(emp.department_id,90,1,0))"90"
from employees emp
group by job_id;