Sie sind auf Seite 1von 5

27) Query to display Name and Commission Amount.

If the employee does not earn commission then use default value No Commission . SQL> UPDATE NEWEMPL 2 SET COMMISSION=NULL WHERE COMMISSION=0; 11 rows updated. SQL> SELECT ENAME, NVL(TO_CHAR(COMMISSION),'No Commission') COMMISSION 2 FROM NEWEMPL;

34) Query to display Name and Employee no. along with their Manger s Name and the Manager s employee no; along with the Employees Name who do not have a Manager. SQL> SELECT E1.ENAME,E1.ENO,E2.ENAME,E2.ENO 2 FROM NEWEMPL E1,NEWEMPLl E2 3 WHERE E1.MANAGER=E2.ENO OR ( E1.MANAGER IS NULL AND E1.ENO=E2.ENO); ENAME --------------KING BLAKE CLARK JONES SCOTT FORD ADAMS MARTIN TURNER JAMES ALLAN ENAME --------------WARD MILLER SMITH ENO --783 769 778 756 788 792 787 765 784 790 749 ENO --752 793 736 ENAME --------------KING KING KING KING JONES JONES CLARK BLAKE BLAKE BLAKE BLAKE ENAME --------------BLAKE SCOTT JAMES ENO --783 783 783 783 756 756 778 769 769 769 769 ENO --769 788 790

35) Query to display the Employee No, Name and Salary for all employees who earn than the average salary and who work in a Department with any employee with any in his/her name. SQL> SELECT ENO,ENAME,SALARY FROM NEWEMPL 2 WHERE DNO IN( SELECT DNO FROM NEWDEP D WHERE D.DNO=DNO AND 3 ENAME LIKE '%T%' AND SALARY > (SELECT AVG(SALARY) FROM NEWEMPL 9)); ENO ENAME SALARY T

--- --------------- ---------788 SCOTT 2850

36) Query to display Name, Dept No. & Salary of any employee whose department No. and salary matches both the department no. and the salary of any empl oyee who earns a commission.

SQL> 2 3 4

SELECT E.ENAME,E.DNO,E.SALARY FROM NEWEMPL E,NEWEMPL E1 WHERE E.ENO=E1.ENO AND E.SALARY=E1.SALARY AND E.DNO=E1.DNO AND E1.COMMISSION > 0;

ENAME DNO SALARY --------------- ---------- ---------WARD 30 1300 ALLAN 30 2000 MARTIN 30 1250

37) Query to display Name, Hire Date of any employee hired after the employee Bl ake was hired by the Company. SQL> select ename ,hire_date from newempl 2 where hire_date > (select hire_date from newempl where ename='blake'); ENAME -------------------------------------------------miller ford james adams turner king scott clark HIRE_DATE --------23-JAN-82 03-DEC-81 03-DEC-81 12-JAN-83 08-SEP-81 17-NOV-81 09-DEC-82 09-JUN-81

38) Query to display Name and Hire Dates of all Employees along with their Manag er s Name and Hire Date for all the employees who were hired before their managers. SQL> SELECT E1.ENAME,E1.HIRE_DATE,E2.ENAME,E2.HIRE_DATE 2 FROM NEWEMPL E1,NEWEMPL E2 3 WHERE E1.MANAGER=E2.ENO AND E1.HIRE_DATE < E2.HIRE_DATE; ENAME --------------BLAKE CLARK HIRE_DATE --------01-MAY-81 09-JUN-81 ENAME --------------KING KING HIRE_DATE --------17-NOV-81 17-NOV-81

JONES MARTIN ALLAN WARD MILLER SMITH

02-APR-81 22-APR-81 20-FEB-81 22-FEB-81 23-JAN-82 17-DEC-80

KING BLAKE BLAKE BLAKE SCOTT JAMES

17-NOV-81 01-MAY-81 01-MAY-81 01-MAY-81 09-DEC-82 03-DEC-81 Each asterisks

39) Query to display Name and Salaries represented by Asteristisks (*) signifying $100.

SQL> SELECT ename ||' '|| rpad(' ', salary/100+1, '*') 2 FROM NEWEMPL; ENAME||''||RPAD('',SALARY/100+1,'*') --------------------------------------------------------------------KING ***************************** JONES *********************** CLARK ***************************** BLAKE **************************** FORD ************************** SCOTT **************************** WARD ************* ALLAN ******************** JAMES ********* TURNER ************** SMITH ********** ENAME||''||RPAD('',SALARY/100+1,'*') --------------------------------------------------------------------ADAMS *********** MARTIN ************ MILLER *************

45) Query to display the Manager s No. & the Salary of the Lowest paid employee fo r that respective manager. Exclude anyone where the Manager ID is not known. Exclude any groups where the minimum salary is less than $1000. SQL> 2 3 4 5 SELECT MANAGER,MIN(SALARY) FROM NEWEMPL WHERE MANAGER IS NOT NULL GROUP BY MANAGER HAVING MIN(SALARY) > 1000;

MAN MIN(SALARY) --- ----------778 1150 788 1300 756 2600 783 2300

46) Query to display the Department Name, Location Name, No. of Employees & the average salary for all employees in that department.

SQL> 2 3 4

SELECT DNAME,LOCATION,COUNT(*),AVG(SALARY) FROM NEWEMPL E,NEWDEP D WHERE E.DNO=D.DNO GROUP BY DNAME,LOCATION; LOCATION COUNT(*) AVG(SALARY) --------------- ---------- ----------DALLAS 5 1980 CHICAGO 6 1636.66667 BOSTON 1 1300 NEW YORK 2 2925

DNAME --------------RESEARCH SALES OPERATION ACCOUNTING

47) Query to display Name and Hire Date for all employees in the same dept. as B lake. SQL> select ename,hire_date from newempl 2 where dno=(select dno from newempl 3 where ename='blake'); ENAME -------------------------------------------------martin ward allan james turner blake HIRE_DATE --------22-APR-81 22-FEB-81 20-FEB-81 03-DEC-81 08-SEP-81 01-MAY-81

49) Query to display Employee Number & Name for all employees who work in a department with any employee whose name contains a T .

SQL> select eno, ename 2 from newempl 3 where dno IN (select dno from newempl where ename like '%t%'); ENO --756 736 788 792 787 765 ENAME -------------------------------------------------jones smith scott ford adams martin

784 790 752 769 749

turner james ward blake allan

52) Select manager name getting salary greater than average salary of employees in his department. SQL> 2 3 roup SQL> select e.ename from newempl e where salary > (select avg(f.salary) from newempl f where f.manager=e.eno g by f.manager);

ENAME -------------------------------------------------king scott clark blake