0% found this document useful (0 votes)
109 views5 pages

Lab Exam Solution

The document contains SQL queries and answers related to retrieving employee data from an EMP database table. It includes queries to list employees by hire date, salary, commission, name characteristics, department and more. Additional queries find maximum salaries, average salaries by department, employees that work for specific managers, and departments with no employees. The final section includes bonus queries to find top earning salespeople and highest paying departments. The queries retrieve data on employees from the EMP table based on dates of hire, salaries, commissions, names, departments and other fields. Results are ordered and filtered in various ways such as by salary, department, manager, and job type. Some queries use subqueries

Uploaded by

Nasif Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views5 pages

Lab Exam Solution

The document contains SQL queries and answers related to retrieving employee data from an EMP database table. It includes queries to list employees by hire date, salary, commission, name characteristics, department and more. Additional queries find maximum salaries, average salaries by department, employees that work for specific managers, and departments with no employees. The final section includes bonus queries to find top earning salespeople and highest paying departments. The queries retrieve data on employees from the EMP table based on dates of hire, salaries, commissions, names, departments and other fields. Results are ordered and filtered in various ways such as by salary, department, manager, and job type. Some queries use subqueries

Uploaded by

Nasif Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

1. List the emps who joined in January.

Ans: select * from emp where to_char (hiredate,’mon’) = ‘jan’;

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.

Ans: select * from emp where comm>sal;

4. List the emps where third character of their name must be ‘r’.

Ans: select * from emp where ENAME like '_ _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');

6. List the emps whose Jobs are same as ALLEN.


Ans: select * from emp where job = (select job from emp where ename = 'ALLEN')
and ename <> 'ALLEN';

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';

9. Select all the employees who work in DALLAS.

Ans: select EMPNO, ENAME, JOB, MGR, HIREDATE, SAL, COMM,


emp.DEPTNO, DNAME, LOC from emp, dept where emp.deptno = dept.deptno
and loc = 'DALLAS';

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.

Ans: select deptno, sum(sal) as TOTAL_SAL from emp where job in


('MANAGER','ANALYST') group by deptno having avg(sal)>=3000;
11. Display all the employees who are getting some commission in department 20 & 30
Ans: select * from emp where NVL(comm,0) <> 0 and deptno in (20,30);

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) ;

14. List the Deptno where there are no emps.

Ans: select deptno from dept where dname not in (select dname from emp, dept
where emp.deptno = dept.deptno group by dname);

15. Display the second maximum salary.

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.

Ans: lect deptno,name,job,sal,sal+nvl(comm.,0) from emp where job = ‘SALESMAN’


and sal in (select max(sal+nvl(comm.,0)) from emp where comm. is not null) Order by
(sal+nvl(comm.,0)) desc

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy