You are on page 1of 4

Practice 4

1. Write a query in SQL to list the employee name, job, and department name.

ENAME JOB DNAME


---------- --------- --------------
CLARK MANAGER ACCOUNTING
KING PRESIDENT ACCOUNTING
MILLER CLERK ACCOUNTING
JONES MANAGER RESEARCH
FORD ANALYST RESEARCH
ADAMS CLERK RESEARCH
SMITH CLERK RESEARCH
SCOTT ANALYST RESEARCH
WARD SALESMAN SALES
TURNER SALESMAN SALES
ALLEN SALESMAN SALES

ENAME JOB DNAME


---------- --------- --------------
JAMES CLERK SALES
BLAKE MANAGER SALES
MARTIN SALESMAN SALES

14 rows selected.

2. Write a query in SQL to list the employee name, job, and location who are either CLERK
or MANAGER.

ENAME JOB LOC


---------- --------- -------------
CLARK MANAGER NEW YORK
MILLER CLERK NEW YORK
ADAMS CLERK DALLAS
JONES MANAGER DALLAS
SMITH CLERK DALLAS
BLAKE MANAGER CHICAGO
JAMES CLERK CHICAGO

7 rows selected.

3. Write a query in SQL to list the employee name, salary, and department name whose
salary is an odd value.
ENAME SAL DNAME
---------- ---------- --------------
JONES 2975 RESEARCH

4. Write a query in SQL to list the employee name, and department name who are not
working under a manager.

ENAME DNAME
---------- --------------
KING ACCOUNTING

5. Write a query in SQL to list the name of employees and their manager separated by the
string 'works for'.
E.ENAME||'WORKSFOR'||M.ENAME
-------------------------------
FORD works for JONES
SCOTT works for JONES
TURNER works for BLAKE
ALLEN works for BLAKE
WARD works for BLAKE
JAMES works for BLAKE
MARTIN works for BLAKE
MILLER works for CLARK
ADAMS works for SCOTT
BLAKE works for KING
JONES works for KING

E.ENAME||'WORKSFOR'||M.ENAME
-------------------------------
CLARK works for KING
SMITH works for FORD

13 rows selected.

6. Write a query in SQL to list the name, salary, manager name, manager's salary for those
employees whose salary is greater than the salary of their managers.

ENAME SAL Manager Manager_Salary


---------- ---------- ---------- --------------
FORD 3000 JONES 2975
SCOTT 3000 JONES 2975
If you have time, complete the following exercises:
7. Write a query in SQL to list the employees name, department name, salary and commission,
for those whose salary is between 2000 and 5000 while location is NEW YORK.

ENAME DNAME SAL COMM


---------- -------------- ---------- ----------
CLARK ACCOUNTING 2450
KING ACCOUNTING 5000

8. Write a query in SQL to list the employees name, job, salary and commission,for those
whose manager name is KING.

ENAME JOB SAL COMM


---------- --------- ---------- ----- -----
BLAKE MANAGER 2850
JONES MANAGER 2975
CLARK MANAGER 2450

If you want extra challenge, complete the following exercises:


9. Write a query in SQL to list the employees (only name, salary, and hiredate) along with their
location who belongs to NEW YORK, CHICAGO with a salary range between 2000 and 5000
and joined in 1981.

ENAME SAL HIREDATE LOC


---------- ---------- ------------ -------------
BLAKE 2850 01-MAY-81 CHICAGO
CLARK 2450 09-JUN-81 NEW YORK
KING 5000 17-NOV-81 NEW YORK

10. Write a query in SQL to list the employees (only name, hiredate, and manager's hiredate)
who are senior to their own manager.

ENAME HIREDATE Manager Join


---------- ------------ ------------
ALLEN 20-FEB-81 01-MAY-81
WARD 22-FEB-81 01-MAY-81
BLAKE 01-MAY-81 17-NOV-81
JONES 02-APR-81 17-NOV-81
CLARK 09-JUN-81 17-NOV-81
SMITH 17-DEC-80 03-DEC-81

6 rows selected.
11. List all the employees (only name, job, salary, and grade) whose salaries are in Grade 2
and Grade 3.

ENAME JOB SAL GRADE


---------- --------- ---------- ----- -----
WARD SALESMAN 1250 2
MARTIN ALESMAN 1250 2
MILLER CLERK 1300 2
ALLEN SALESMAN 1600 3
TURNER SALESMAN 1500 3

You might also like