You are on page 1of 23

Day 1

1. List all the information about the employees in the EMP table. QUERY : select * from emp; OUTPUT: EMPNO ENAME JOB MGR HIREDATE -------------- ------------------ --------7369 SMITH CLERK 7902 17-DEC-80 7499 ALLEN SALESMAN 7698 20-FEB-81 7521 WARD SALESMAN 7698 22-FEB-81 7566 JONES MANAGER 7839 02-APR-81 7654 MARTIN SALESMAN 7698 28-SEP-81 7698 BLAKE MANAGER 7839 01-MAY-81 7782 CLARK MANAGER 7839 09-JUN-81 7788 SCOTT ANALYST 7566 19-APR-87 7839 KING PRESIDENT 17-NOV-81 7844 TURNER SALESMAN 7698 08-SEP-81 7876 ADAMS CLERK 7788 23-MAY-87 7900 JAMES CLERK 7698 03-DEC-81 7902 FORD ANALYST 7566 03-DEC-81 7934 MILLER CLERK 7782 23-JAN-82 SAL ---------800 1600 1250 2975 1250 2850 2450 3000 5000 1500 1100 950 3000 1300 COMM ---------300 500 1400 DEPTNO -----------20 30 30 20 30 30 10 20 10 30 20 30 20 10

2. List all the information about the departments in the DEPT table. QUERY : select * from dept; OUTPUT: DEPTNO DNAME LOC ---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 3. List the employees number,name,job title and hiredate of employees. QUERY : select empno, ename, job, hiredate from emp; OUTPUT: EMPNO ENAME JOB -------- ---------- --------7369 SMITH CLERK 7499 ALLEN SALESMAN HIREDATE --------17-DEC-80 20-FEB-81

7521 WARD 7566 JONES 7654 MARTIN 7698 BLAKE 7782 CLARK 7788 SCOTT 7839 KING 7844 TURNER 7876 ADAMS 7900 JAMES 7902 FORD 7934 MILLER

SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST PRESIDENT SALESMAN CLERK CLERK ANALYST CLERK

22-FEB-81 02-APR-81 28-SEP-81 01-MAY-81 09-JUN-81 19-APR-87 17-NOV-81 08-SEP-81 23-MAY-87 03-DEC-81 03-DEC-81 23-JAN-82

4. Display name,job,salary,annual salary of all employees. QUERY : select ename, job, sal,sal*12 from emp; OUTPUT: ENAME ---------SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER JOB --------CLERK SALESMAN SALESMAN MANAGER SALESMAN MANAGER MANAGER ANALYST PRESIDENT SALESMAN CLERK CLERK ANALYST CLERK SAL SAL*12 ---------- ---------800 9600 1600 19200 1250 15000 2975 35700 1250 15000 2850 34200 2450 29400 3000 36000 5000 60000 1500 18000 1100 13200 950 11400 3000 36000 1300 15600

5. List contents of salgrade table. QUERY : select * from salgrade; OUTPUT: GRADE -----1 2 3 4 5 LOSAL ---------700 1201 1401 2001 3001 HISAL ---------1200 1400 2000 3000 9999

6. Display all the different job types. QUERY : select distinct job from emp; OUTPUT: JOB --------CLERK SALESMAN PRESIDENT MANAGER 7. Select the name and salary of all employees who are CLERK. QUERY : SELECT ENAME, SAL from EMP WHERE JOB='CLERK'; OUTPUT: ENAME ---------SMITH ADAMS JAMES MILLER SAL ---------800 1100 950 1300

8. List the employees number, name, job title, salary and hiredate of employees of department number 20. QUERY : SELECT EMPNO, ENAME, JOB, SAL, HIREDATE FROM EMP WHERE DEPTNO=20; OUTPUT: EMPNO ENAME ---------- ---------7369 SMITH 7566 JONES 7788 SCOTT 7876 ADAMS 7902 FORD JOB --------CLERK MANAGER ANALYST CLERK ANALYST SAL HIREDATE ---------- --------800 17-DEC-80 2975 02-APR-81 3000 19-APR-87 1100 23-MAY-87 3000 03-DEC-81

9. List the name, job title and salary of everyone hired on December 17, 1980. QUERY : SELECT ENAME, JOB, SAL FROM EMP WHERE HIREDATE= '17-DEC-80'; OUTPUT: ENAME JOB ---------- --------- ---------SMITH CLERK SAL 800

10. List the department name and department number for departments with numbers greater than or equal to 20. QUERY : select dname, deptno from dept where deptno>=20; OUTPUT: DNAME -------------RESEARCH SALES OPERATIONS DEPTNO ---------20 30 40

11. Select the name, salary and commission of employees whose commission is greater than their salary. QUERY : select ename, sal,comm from emp where comm>sal; OUTPUT: ENAME ---------MARTIN SAL ---------1250 COMM ---------1400

12. List the names of employees where salary is less than 2500. QUERY : select ename from emp where sal<2500; OUTPUT: ENAME ---------SMITH ALLEN WARD MARTIN CLARK TURNER ADAMS JAMES MILLER

13. List the names and employee number of managers who earn more than 2600. Display in alphatical order by name. QUERY : select ename, empno from emp where job='MANAGER' AND SAL>2600 ORDER BY ename; OUTPUT: ENAME EMPNO ---------- ---------BLAKE 7698 JONES 7566

14. Select the information about manager and the president from the column job in the EMP table. Order the resume by department number. QUERY : select * from emp where job IN('MANAGER','PRESIDENT') ORDER BY DEPTNO; OUTPUT: EMPNO ENAME ------ ---------7839 KING 7782 CLARK 7566 JONES 7698 BLAKE JOB MGR HIREDATE ------------------ --------PRESIDENT 17-NOV-81 MANAGER 7839 09-JUN-81 MANAGER 7839 02-APR-81 MANAGER 7839 01-MAY-81 SAL ---------5000 2450 2975 2850 COMM ---------DEPTNO ---------10 10 20 30

DAY 2
1. List all the employees names that do not end in S. QUERY : SELECT ENAME FROM EMP WHERE ENAME NOT LIKE '%S'; OUTPUT: ENAME ---------SMITH ALLEN WARD MARTIN BLAKE CLARK SCOTT KING TURNER FORD MILLER 2. List the employees names that start with C. QUERY : SELECT ENAME FROM EMP WHERE ENAME LIKE 'C%'; OUTPUT: ENAME ---------CLARK 3. List the name,job and department of everyone whose name falls in the alphabetical range C to L. QUERY : SELECT ENAME, JOB, DEPTNO FROM EMP WHERE ENAME BETWEEN 'C%' AND 'L%'; OUTPUT: ENAME JOB -----------------JONES MANAGER CLARK MANAGER KING PRESIDENT JAMES CLERK FORD ANALYST DEPTNO ---------20 10 10 30 20

4. List employee details working in department 20, 30 or 40. QUERY : SELECT * FROM EMP WHERE DEPTNO IN(20,30,40);

OUTPUT: EMPNO ENAME -------------7369 SMITH 7499 ALLEN 7521 WARD 7566 JONES 7654 MARTIN 7698 BLAKE 7788 SCOTT 7844 TURNER 7876 ADAMS 7900 JAMES 7902 FORD

JOB --------CLERK SALESMAN SALESMAN MANAGER SALESMAN MANAGER ANALYST SALESMAN CLERK CLERK ANALYST

MGR ---------7902 7698 7698 7839 7698 7839 7566 7698 7788 7698 7566

HIREDATE --------17-DEC-80 20-FEB-81 22-FEB-81 02-APR-81 28-SEP-81 01-MAY-81 19-APR-87 08-SEP-81 23-MAY-87 03-DEC-81 03-DEC-81

SAL ---------800 1600 1250 2975 1250 2850 3000 1500 1100 950 3000

COMM ---------300 500 1400 0

DEPTNO ---------20 30 30 20 30 30 20 30 20 30 20

5. List the employees while names start with T and ends with R. QUERY : SELECT ENAME FROM EMP WHERE ENAME LIKE 'T%R'; OUTPUT: ENAME ---------TURNER 6. Display all employee names which have TH or LL in them. QUERY : SELECT ENAME FROM EMP WHERE ENAME LIKE '%TH%' OR ENAME LIKE '%LL%'; OUTPUT: ENAME ---------SMITH ALLEN MILLER 7. Display all employees who are hired during 1987. QUERY : SELECT * FROM EMP WHERE HIREDATE LIKE '%87%'; OUTPUT: EMPNO ENAME ------ ---------7788 SCOTT 7876 ADAMS JOB --------ANALYST CLERK MGR HIREDATE ---------- --------7566 19-APR-87 7788 23-MAY-87 SAL ---------3000 1100 COMM ---------DEPTNO ---------20 20

8,9,10,11,12. Display the data as shown below for all employees. Who, what and when QUERY : SELECT ENAME || ' HAS HELD THE POSITION OF '|| JOB||' IN DEPT '||DEPTNO||' SINCE '||HIREDATE FROM EMP;

OUTPUT: SMITH HAS HELD THE POSITION OF CLERK IN DEPT 20 SINCE 17-DEC-80 ALLEN HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 20-FEB-81 WARD HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 22-FEB-81 JONES HAS HELD THE POSITION OF MANAGER IN DEPT 20 SINCE 02-APR-81 MARTIN HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 28-SEP-81 BLAKE HAS HELD THE POSITION OF MANAGER IN DEPT 30 SINCE 01-MAY-81 CLARK HAS HELD THE POSITION OF MANAGER IN DEPT 10 SINCE 09-JUN-81 SCOTT HAS HELD THE POSITION OF ANALYST IN DEPT 20 SINCE 19-APR-87 KING HAS HELD THE POSITION OF PRESIDENT IN DEPT 10 SINCE 17-NOV-81 TURNER HAS HELD THE POSITION OF SALESMAN IN DEPT 30 SINCE 08-SEP-81 ADAMS HAS HELD THE POSITION OF CLERK IN DEPT 20 SINCE 23-MAY-87 JAMES HAS HELD THE POSITION OF CLERK IN DEPT 30 SINCE 03-DEC-81 FORD HAS HELD THE POSITION OF ANALYST IN DEPT 20 SINCE 03-DEC-81 MILLER HAS HELD THE POSITION OF CLERK IN DEPT 10 SINCE 23-JAN-82 13. List the details of the employees in department10 and 20 in alphatical order of names. QUERY : SELECT * FROM EMP WHERE DEPTNO IN(10,20) ORDER BY ENAME; OUTPUT: EMPNO ENAME -------------7876 ADAMS 7782 CLARK 7902 FORD 7566 JONES 7839 KING 7934 MILLER 7788 SCOTT 7369 SMITH JOB --------CLERK MANAGER ANALYST MANAGER PRESIDENT CLERK ANALYST CLERK MGR HIREDATE ---------- --------7788 23-MAY-87 7839 09-JUN-81 7566 03-DEC-81 7839 02-APR-81 17-NOV-81 7782 23-JAN-82 7566 19-APR-87 7902 17-DEC-80 SAL ---------1100 2450 3000 2975 5000 1300 3000 800 COMM ---------DEPTNO ---------20 10 20 20 10 10 20 20

14. List all row form EMP table, by converting the NULL value in COMM column to ZERO(use NVL command). QUERY : SELECT NVL(COMM,0) FROM EMP; OUTPUT: NVL(COMM,0) ----------0 300 500 0 1400 0 0 0 0

0 0 0 0 0 15. List all manager and salesman with salaries over 1500/-. QUERY : SELECT ENAME FROM EMP WHERE JOB IN('MANAGER','SALESMAN') AND SAL>1500; OUTPUT: ENAME ---------ALLEN JONES BLAKE CLARK 16. Write a query that will accept a given job title and displays all records according to that title. QUERY : SELECT * FROM EMP WHERE JOB = '&JOB_TITLE'; OUTPUT: Enter value for JOB_TITLE: MANAGER old 1: SELECT * FROM EMP WHERE JOB = '& JOB_TITLE ' new 1: SELECT * FROM EMP WHERE JOB = 'MANAGER' EMPNO ENAME ---------- ---------7566 JONES 7698 BLAKE 7782 CLARK JOB --------MANAGER MANAGER MANAGER MGR HIREDATE ---------- --------7839 02-APR-81 7839 01-MAY-81 7839 09-JUN-81 SAL COMM DEPTNO ---------- ---------- ---------2975 20 2850 30 2450 10

17. List of employees who do not get any commission. QUERY : SELECT ENAME FROM EMP WHERE COMM IS NULL; OUTPUT: ENAME ---------SMITH JONES BLAKE CLARK SCOTT KING ADAMS JAMES FORD MILLER

DAY 3
1. List the names and hiredates of the employees in department 20. Display the hiredate formatted as 12/03/84. QUERY : select ename, to_char(hiredate,'dd/mm/yy') from emp where deptno=20; OUTPUT: ENAME ---------SMITH JONES SCOTT ADAMS FORD TO_CHAR( -------17/12/80 02/04/81 19/04/87 23/05/87 03/12/81

2. How many months has the president worked for the company? Round to the nearest whole number of months. QUERY : SELECT ROUND(MONTHS_BETWEEN(SYSDATE,HIREDATE)) FROM EMP WHERE JOB='PRESIDENT'; OUTPUT: ROUND(MONTHS_BETWEEN(SYSDATE,HIREDATE)) ----358 3. List the names of all employees whose hiredate is in the month of December (use substr()function).

QUERY : select ename from emp where substr(HIREDATE,4,3)='DEC'; OUTPUT: ENAME -------------SMITH JAMES FORD 4. Give SQL command to find the average annual salary per job in each department. QUERY : select job,avg(sal*12) from emp group by job; OUTPUT: JOB AVG(SAL*12) ------------------CLERK 12450 SALESMAN 16800 PRESIDENT 60000

MANAGER ANALYST

33100 36000

5. Count the number of people in department 30. QUERY : select count(*) from emp where deptno=30; OUTPUT: COUNT(*) ---------6 6. Compute the average, minimum and maximum slsries of employee for each department. QUERY : select deptno, avg(sal),min(sal),max(sal) from emp group by deptno; OUTPUT: DEPTNO AVG(SAL) MIN(SAL) MAX(SAL) ---------- ---------------------------30 1566.66667 950 2850 20 2175 800 3000 10 2916.66667 1300 5000

7. Display the deptnos where morethan two clerks are working. QUERY : SELECT DEPTNO FROM EMP WHERE JOB='CLERK' GROUP BY DEPTNO HAVING COUNT(*)>2; OUTPUT: no rows selected

8, 9. Produce the following output: EMPLOYEE SMITH(CLERK) ALLEN(SALESMAN) QUERY : SELECT ENAME || '(' || JOB || ')' FROM EMP; OUTPUT: ENAME||'('||JOB||')' --------------------SMITH(CLERK) ALLEN(SALESMAN)

WARD(SALESMAN) JONES(MANAGER) MARTIN(SALESMAN) BLAKE(MANAGER) CLARK(MANAGER) SCOTT(ANALYST) KING(PRESIDENT) TURNER(SALESMAN) ADAMS(CLERK) JAMES(CLERK) FORD(ANALYST) MILLER(CLERK) 10. Who was the first employee hired in each department. QUERY : SELECT ENAME FROM EMP WHERE HIREDATE IN(SELECT MIN(HIREDATE) FROM EMP GROUP BY DEPTNO ; OUTPUT: ENAME -------------ALLEN SMITH CLARK 11. Create a view consisting of employees and their total sum of salary dept wise. QUERY : create view emp1 as select ename,sal from emp order by deptno; 12. How many employee works in New York? QUERY : SELECT COUNT(*) FROM EMP WHERE DEPTNO IN(SELECT DEPTNO FROM DEPT WHERE LOC='NEW YORK') OUTPUT: COUNT(*) --------------3

13. Write a query to display as following: ENAME HIRE_DATE ----------- ----------------SMITH DECEMBER,SEVENTEEN 1980 ALLEN FEBRUARY,TWENTY 1981 WARD FEBRUARY,TWENTY TWO 1981 QUERY : select ename,to_char(hiredate,month,ddsp,yyyy) as HIRE_DATE from emp; OUTPUT: ENAME HIRE_DATE ----------- ----------------SMITH DECEMBER,SEVENTEEN 1980 ALLEN FEBRUARY,TWENTY 1981 WARD FEBRUARY,TWENTY TWO 1981 JONES APRIL,TWO 1981 MARTIN SEPTEMBER, TWENTY EIGHT1981 BLAKE MAY,ONE 1981 CLARK JUNE,NINE 1981 SCOTT APRIL,NINETEEN 1987 KING NOVEMBER,SEVENTEEN 1981 TURNER SEPTEMBER,EIGHT 1981 ADAMS MAY, TWENTY THREE 1987 JAMES DECEMBER, THREE 1981 FORD DECEMBER,THREE 1981 MILLER JANUARY, TWENTY TWO 1982 14. Print a list of employees display just salary if more than 1500 if exactry 1500 display on target if less than 1500 display below 1500. QUERY : select ename,(case when sal>1500 then sal when sal=1500 then 'on target' when sal<1500 then 'below 1500' end)as salary from emp; 15. Determine the average salary of employees. QUERY : SELECT AVG(SAL) FROM EMP; OUTPUT: AVG(SAL) ---------2073.21429 16. List department number, department name , location local commission paid and total salary of each department .

QUERY : SELECT DEPT.DEPTNO, DEPT.DNAME, DEPT.LOC,EMP.COMM,EMP.SAL FROM DEPT LEFT JOIN EMP ON DEPT.DEPTNO=EMP.DEPTNO; OUTPUT: DEPTNO DNAME ---------- -------------20 RESEARCH 30 SALES 30 SALES 20 RESEARCH 30 SALES 30 SALES 10 ACCOUNTING 20 RESEARCH 10 ACCOUNTING 30 SALES 20 RESEARCH 30 SALES 20 RESEARCH 10 ACCOUNTING 40 PERATIONS LOC ------------DALLAS CHICAGO CHICAGO DALLAS CHICAGO CHICAGO NEW YORK DALLAS NEW YORK CHICAGO DALLAS CHICAGO DALLAS NEW YORK BOSTON COMM SAL ---------- ---------800 300 1600 500 1250 2975 1400 1250 2850 2450 3000 5000 0 1500 1100 950 3000 1300

17. Display the average monthly salary bill for each job type within a department. QUERY : select job, deptno, avg(sal) from emp group by job,deptno; OUTPUT: JOB --------MANAGER PRESIDENT CLERK SALESMAN ANALYST MANAGER MANAGER CLERK CLERK DEPTNO ---------20 10 10 30 20 30 10 30 20 AVG(SAL) ---------35700 60000 15600 16800 36000 34200 29400 11400 11400

18. To display only those jobs where the minimum salary is greater than or equal to 3000. QUERY : select distinct job from emp where sal>=3000; OUTPUT: JOB --------PRESIDENT ANALYST

19. Find the average salary and average total remuneration for each job type remember salesman earn commission. QUERY : SELECT AVG(SAL), AVG((SAL+COMM)*12), JOB FROM EMP GROUP BY JOB; OUTPUT: AVG(SAL) AVG((SAL+COMM)*12) --------------------------1037.5 1400 23400 5000 2758.33333 3000 JOB -------CLERK SALESMAN PRESIDENT MANAGER ANALYST

20. Find out the difference between highest and lowest salaries. QUERY : SELECT MAX(SAL)-MIN(SAL) FROM EMP; OUTPUT: MAX(SAL)-MIN(SAL) ----------------4200 21. Find all departments which have more than 3 employees. QUERY : SELECT DNAME FROM DEPT WHERE DEPTNO IN( SELECT DEPTNO FROM EMP GROUP BY DEPTNO HAVING COUNT(*)>3); OUTPUT: DNAME -------------SALES RESEARCH 22. To display only those jobs where the maximum salary is greater than or equal to 3000. QUERY : select distinct job from emp where (sal+NVL(comm,0))>=3000; OUTPUT: JOB -----------PRESIDENT ANALYST

23. List lowest paid employee working for each manager , exclude any group where the minimum salary is less than 1000 sort the out by salary. QUERY : select manager,min(sal) from (select m.ename as manager,e.sal from emp m join emp e on e.mgr=m.empno) group by manager having min(sal)>1000 order by 2; OUTPUT: MANAGER ---------FORD BLAKE SCOTT CLARK KING JONES MIN(SAL) ---------9600 11400 13200 15600 29400 36000

DAY- 4
1. Display all employees name and their department name in department name order. QUERY : SELECT EMP.ENAME, DEPT.DNAME FROM EMP LEFT JOIN DEPT ON DEPT.DEPTNO=EMP.DEPTNO ORDER BY DNAME; OUTPUT: ENAME DNAME --------------------------------------CLARK ACCOUNTING KING ACCOUNTING MILLER ACCOUNTING SCOTT RESEARCH ADAMS RESEARCH FORD RESEARCH JONES RESEARCH SMITH RESEARCH JAMES SALES TURNER SALES BLAKE SALES MARTIN SALES WARD SALES ALLEN SALES 2. Display all employee name, department number and name. QUERY : SELECT EMP.ENAME, EMP.DEPTNO, DEPT.DNAME FROM EMP LEFT JOIN DEPT ON DEPT.DEPTNO=EMP.DEPTNO OUTPUT: ENAME DEPTNO DNAME --------- -------------- ---------------MILLER 10 ACCOUNTING KING 10 ACCOUNTING CLARK 10 ACCOUNTING FORD 20 RESEARCH ADAMS 20 RESEARCH SCOTT 20 RESEARCH JONES 20 RESEARCH SMITH 20 RESEARCH JAMES 30 SALES TURNER 30 SALES BLAKE 30 SALES MARTIN 30 SALES WARD 30 SALES

3. Display the department that has no employee. QUERY : select deptno from dept where deptno not in(select deptno from emp); OUTPUT: DEPTNO ---------40 4. Find all employees who joined the company before their manager. QUERY : select e.ename as employee, m.ename as manager from emp m JOIN emp e ON e.mgr = m.empno where e.hiredate <m.hiredate; OUTPUT: EMPLOYEE ------------WARD ALLEN CLARK BLAKE JONES SMITH MANAGER --------------BLAKE BLAKE KING KING KING FORD

5. Find the employees who earn more than the lowest salary in each department. QUERY : select ename, deptno, sal from emp where sal in(select sal from emp where sal not in(select min (sal) from emp group by deptno)); OUTPUT: ENAME ---------ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS FORD DEPTNO ---------30 30 20 30 30 10 20 10 30 20 20 SAL ---------19200 15000 35700 15000 34200 29400 36000 60000 18000 13200 36000

6. Display employee who earn more than the salary in department 30 QUERY : SELECT ENAME FROM EMP WHERE SAL>(SELECT MIN(SAL) FROM EMP WHERE DEPTNO=30); OUTPUT: ENAME -------------------------ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS FORD MILLER 7. Find employees who earn more than every employee in department 30 QUERY : SELECT ENAME FROM EMP WHERE SAL>(SELECT MAX(SAL) FROM EMP WHERE DEPTNO=30); OUTPUT: ENAME ----------JONES SCOTT KING FORD 8. Find the job with highest average salary QUERY : select job from(select job, avg(sal), row_number() over(order by avg(sal) desc) rn from emp group by job) where rn<2; OUTPUT: JOB --------PRESIDENT

9. To display all employees who earn less than their managers. QUERY : select e.ename as employee, m.ename as manager from emp m JOIN emp e ON e.mgr = m.empno where e.sal <m.sal; OUTPUT: EMPLOYEE MANAGER ---------------- ---------------------------JAMES BLAKE TURNER BLAKE MARTIN BLAKE WARD BLAKE ALLEN BLAKE MILLER CLARK ADAMS SCOTT CLARK KING BLAKE KING JONES KING SMITH FORD 10. Display the name of job, hiredate for employees whose salary is greater than the highest salary in any SALES department QUERY : SELECT JOB, HIREDATE FROM EMP WHERE SAL>(SELECT MAX(EMP.SAL) FROM DEPT LEFT OUTER JOIN EMP ON DEPT.DEPTNO= EMP.DEPTNO WHERE DEPT.DNAME='SALES'); OUTPUT: JOB -----------------MANAGER ANALYST PRESIDENT ANALYST HIREDATE -------------------02-APR-81 19-APR-87 17-NOV-81 03-DEC-81

11. Find out names of the employees salary 2000 and working under FORD, BLAKE, and KING. .(use set operators) QUERY : SELECT E.ENAME AS EMPLOYEE,M.ENAME AS MANAGER FROM EMP M JOIN EMP E ON E.MGR = M.EMPNO WHERE E.SAL>2000 AND M.ENAME IN('FORD','BLAKE','KING'); OUTPUT: EMPLOYEE MANAGER ---------------- -----------------JONES KING BLAKE KING CLARK KING

12. Find out all the job either in department 20 or where salary is greater than 3000. (use set operators) QUERY : SELECT JOB FROM EMP WHERE DEPTNO=20 UNION SELECT JOB FROM EMP WHERE SAL>3000; OUTPUT: JOB -------------ANALYST CLERK MANAGER PRESIDENT

DAY-5
1. Find out the employees who the highest salary in each department. QUERY: SELECT ENAME FROM EMP WHERE SAL IN(SELECT MAX(SAL) FROM EMP GROUP BY DEPTNO; OUTPUT: ENAME -------------------BLAKE FORD SCOTT KING 2. Display the employees who are doing the same job as FORD. QUERY: SELECT ENAME FROM EMP WHERE JOB = (SELECT JOB FROM EMP WHERE ENAME='FORD'); OUTPUT: ENAME -----------SCOTT FORD 3. List the employees name and minimum salary earned by employee in each department. QUERY: SELECT ENAME,DEPTNO,SAL FROM EMP WHERE SAL IN(SELECT MIN(SAL) FROM EMP GROUP BY DEPTNO); OUTPUT: ENAME DEPTNO SAL ---------- ---------------JAMES 30 950 SMITH 20 800 MILLER 10 1300 4. List the top three earners in the company. Display their names and salary. QUERY: SELECT ENAME,SAL FROM (SELECT ename ,sal,ROW_NUMBER() OVER(ORDER BY sal DESC) rn FROM emp) WHERE rn < 4; OUTPUT: ENAME SAL -------- ------KING 5000 SCOTT 3000 FORD 3000

5. Display the employee working in TURNERS department QUERY: SELECT ENAME FROM EMP WHERE DEPTNO=(SELECT DEPTNO FROM EMP WHERE ENAME='TURNER'); OUTPUT: ENAME -----------------------ALLEN WARD MARTIN BLAKE TURNER JAMES

You might also like