ASSIGNMENT #04
1) List the number of employees and average salary for employees in
department 20.
select count(ename) , avg(sal) from emp where emp.deptno=20;
2) List name, salary and PF amount of all employees. (PF is calculated
as 10% of basic salary)
select ename , sal "salary" ,sal*0.1 "PF" from emp;
3) List names of employees who are more than 2 years old in the
company.
select ename from emp where round (sysdate - hiredate) > 2;
select ename from emp where months_between (sysdate,hiredate)/12 >
2;
4) List the employee details in the ascending order of their basic salary.
select * from emp order by sal;
5) List the employee name and hire date in the descending order of the
hire date.
select ename, hiredate from emp order by hiredate desc ;
6) List employee name, salary, PF, HRA, DA and gross; order the
results in the ascending order of gross. HRA is 50% of the salary and
DA is 30% of the salary.
select ename , sal, sal*0.1 "PF" , sal*0.5 "HRA", sal*0.3 "DA" ,
sal+sal*0.1+sal*0.5+sal*0.3 "Gross" from emp order by
sal+sal*0.1+sal*0.5+sal*0.3 ;
select ename , sal, sal*0.1 "PF" , sal*0.5 "HRA", sal*0.3 "DA" ,
sal+sal*0.1+sal*0.5+sal*0.3 as Gross from emp order by Gross ;
7) List the department numbers and number of employees in each
department.
select deptno , count(ename) from emp group by deptno;
8) List the department number and total salary payable in each
department.
select deptno , sum(sal) from emp group by deptno;
9) List the jobs and number of employees in each job. The result should
be in the descending order of the number of employees.
select job , count(empno) from emp group by job order by
count(empno) desc ;
select job , count(empno) as c from emp group by job order by c desc ;
10) List the total salary, maximum and minimum salary and average
salary of the employees job wise.
select job ,sum(sal) , max(sal), min(sal) , avg(sal) from emp group by
job;
11) List the total salary, maximum and minimum salary and average
salary of the employees, for department 20.
select sum(sal) , max(sal), min(sal) , avg(sal) from emp where
emp.deptno=20;
12) List the total salary, maximum and minimum salary and average
salary of the employees job wise, for department 20 and display only
those rows having a average salary > 1000
select job deptno,sum(sal) , max(sal), min(sal) , avg(sal) from emp
where emp.deptno=20 group by job having avg(sal) > 1000 ;