BÀI THỰC HÀNH SỐ 5 – ORACLE
(Hàm nhóm dữ liệu)
1. Hiển thị mức lương cao nhất, thấp nhất, trung bình và tổng số những nhân viên mà
cụm từ ‘REP’ có trong job_id .
2. Hiển thị ngày vào làm việc xa nhất và gần nhất của nhân viên.
Select maxhire_date),min(hire_date)
From employees;
3. Cho biết tổng số nhân viên có id của department là 50.
Select count(employee_id)
From employees
Where department_id =50;
4. Cho biết số nhân viên cuả department_id 80 có được commission_pct.
Select count(employee_id)
From employees
Where department_id =80 and commission_pct is not null ;
5. Cho biết commission_pct trung bình cuả các nhân viên.
Select avg(commission_pct)
From employees;
Select avg(commission_pct)
From employees
Where commission_pct is not null ;
6. Cho biết commission_pct trung bình cuả tất cả nhân viên (những nhân viên không có
commission_pct thì tính là 0) .
Select avg(nvl(commission_pct,0))
From employees;
7. Hiển thị department_id, mức lương trung bình (mức lương trung bình tính dựa theo
department_id).
Select department_id,avg(salary)
From employees
Group by department_id;
8. Như câu 7 nhưng yêu cầu sắp xếp theo thứ tự tăng dần theo mức lương trung bình.
Group by job_id
Having sum(salary)>12000
Order by sum(salary) desc;
select job_id,sum(salary)
from employees
group by job_id
having job_id not like '%REP%' and sum(salary)>12000
order by sum(salary) desc;
12. Hiển thị mức lương trung bình cao nhất tính dựa theo department_id.
Select max(avg(salary))
From employees
Group by department_id;