Lab Exam Solution
Lab Exam Solution
2. List all the emps except ‘PRESIDENT’ & ‘MGR” in asc order of Salaries.
Ans: Select * from emp where job not in (‘PRESIDENT’,’MANAGER’) order by sal
asc;
3. Display all the details of the emps whose Comm. Is more than their Sal.
4. List the emps where third character of their name must be ‘r’.
5. List the details of the emps whose Salaries more than the employee BLAKE.
Ans: select * from emp where sal>(select sal from emp where ename = 'BLAKE');
7. List the Empno, Ename, Sal, Daily sal of all emps in the asc order of Annsal.
Ans: select empno ,ename ,sal,sal/30,12*sal annsal from emp order by annsal asc ;
8. Get all the employees who work in the same departments as of SCOTT.
Ans: select * from emp where deptno = (select deptno from emp where ename =
'SCOTT') and ENAME <> 'SCOTT';
10. Display department-wise total salaries for all the Managers and Analysts, only if the
average salaries for the same is greater than or equal to 3000.
12. Select department name & location of all the employees working for CLARK.
Ans: select DNAME, LOC from emp, dept where emp.deptno = dept.deptno and
mgr = (select empno from emp where ename = 'CLARK');
13. List the name of the dept where more than average no. of emps are working.
Ans: select dname, count(*) from emp, dept where emp.deptno = dept.deptno group
by dname having count(*)>(select avg(count(*)) from emp, dept where emp.deptno
= dept.deptno group by dname) ;
Ans: select deptno from dept where dname not in (select dname from emp, dept
where emp.deptno = dept.deptno group by dname);
Ans: select max(sal) from emp where sal<(select max(sal) from emp);
16. Bonus:
a) List the Deptno, Name, Job, Salary and Sal+Comm of the SALESMAN who are earning
maximum salary and commission in descending order.
b) List out the Name, Job, Salary of the emps in the department with the highest average
salary.
Ans: select * from emp where deptno in (select deptno from emp e having avg(sal)
=(select max(avg(sal)) from emp group by deptno) group by deptno);
17.