ASSIGNMENT-02
1. List details of employees who have joined before 30 Sep 81.
SQL> select * from employeess where hiredate<'30-sep-81';
EMPNO ENAME

JOB

MGR

HIREDATE

SAL

---------- ----------

---------

--------

---------------

----------

7369 SMITH

CLERK

7902

17-DEC-80

800

7499 ALLEN

SALESMAN

7698

20-FEB-81

1600

300

30

7521 WARD

SALESMAN 7698

22-FEB-81

1250

500

30

7566 JONES

MANAGER

7839

02-APR-81

2975

7654 MARTIN

SALESMAN

7698

28-SEP-81

1250

7698 BLAKE

MANAGER

7839

01-MAY-81

2850

30

7782

MANAGER

7839

09-JUN-81

2450

10

SALESMAN

7698

08-SEP-81

1500

CLARK

7844 TURNER

COMM

DEPTNO

---------- ---------20

20
1400

0

30

30

8 rows selected.
2. List names of employees who are not managers.
SQL> select ename from employeess where job!='manager';
ENAME
---------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
Antesh Kumar Singh
Roll No.121379

Page 13
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
3. List the names of employees whose employee numbers are 7369, 7521, 7839, 7934, 7788.
SQL> select ename from employeess where empno in (7369,7521,7839,7934,7788);
ENAME
---------SMITH
WARD
SCOTT
KING
MILLER
5 rows selected.
4. List employees not belonging to department 30, 40, or 10.
SQL> select ename from employeess where deptno not in(30,40,10);
ENAME
---------SMITH
JONES
SCOTT
ADAMS
FORD
5 rows selected.
Antesh Kumar Singh
Roll No.121379

Page 14
5. List employee names for those who have joined between 30 June and 31 Dec. „81.
SQL> select ename from employeess where hiredate between '30-june-81' and '31-dec-81';
ENAME
---------MARTIN
KING
TURNER
JAMES
FORD
6. List the different designations in the company.
SQL> select distinct job from employeess;
JOB
--------CLERK
SALESMAN
PRESIDENT
MANAGER
ANALYST
5 rows selected.
7. List the employees not assigned to any department.
SQL> select ename from employeess where job is NULL;
no rows selected.

8. List the maximum salary paid to a salesman.
SQL> select max(sal) from employeess where job='SALESMAN';
MAX(SAL)
---------1600
Antesh Kumar Singh
Roll No.121379

Page 15
9. List the names of employees who are not eligible for commission.
SQL> select ename from employeess where comm is NULL;

ENAME
---------SMITH
JONES
BLAKE
CLARK
SCOTT
KING
ADAMS
JAMES
FORD
MILLER
10 rows selected.
10. List the name and designation of the employee who does not report to anybody.
SQL> select ename,job from employeess where job='PRESIDENT';
ENAME

JOB

----------

---------

KING

PRESIDENT

Antesh Kumar Singh
Roll No.121379

Page 16
11. List the employees who are eligible for commission.
SQL> select ename from employeess where job is not NULL;
ENAME
---------SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected.
12. List employees whose names either start or end with “S”.
SQL> select ename from emp where ename like 'S%' or ename like '%S';
ENAME
---------SMITH
JONES
SCOTT
Antesh Kumar Singh
Roll No.121379

Page 17
ADAMS
JAMES
5 rows selected.
13. List the number of employees working with the company.
SQL> select count(ename) from emp;
COUNT(ENAME)
-----------14
14. List the number of designations available in the EMP table.
SQL> select count(distinct job) from emp;
COUNT(DISTINCTJOB)
-----------------5
15. List the total salaries paid to the employees.
SQL> select sum(sal) from emp;
SUM(SAL)
---------29025
16. List the maximum, minimum and average salary in the company.
SQL> select max(sal), min(sal), avg(sal) from emp;
MAX(SAL) MIN(SAL)

AVG(SAL)

----------

----------

----------

5000

800

2073.21429

Antesh Kumar Singh
Roll No.121379

Page 18

Assignment 2 (16-08-2013)

  • 1.
    ASSIGNMENT-02 1. List detailsof employees who have joined before 30 Sep 81. SQL> select * from employeess where hiredate<'30-sep-81'; EMPNO ENAME JOB MGR HIREDATE SAL ---------- ---------- --------- -------- --------------- ---------- 7369 SMITH CLERK 7902 17-DEC-80 800 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30 7566 JONES MANAGER 7839 02-APR-81 2975 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 MANAGER 7839 09-JUN-81 2450 10 SALESMAN 7698 08-SEP-81 1500 CLARK 7844 TURNER COMM DEPTNO ---------- ---------20 20 1400 0 30 30 8 rows selected. 2. List names of employees who are not managers. SQL> select ename from employeess where job!='manager'; ENAME ---------SMITH ALLEN WARD JONES MARTIN BLAKE CLARK Antesh Kumar Singh Roll No.121379 Page 13
  • 2.
    SCOTT KING TURNER ADAMS JAMES FORD MILLER 14 rows selected. 3.List the names of employees whose employee numbers are 7369, 7521, 7839, 7934, 7788. SQL> select ename from employeess where empno in (7369,7521,7839,7934,7788); ENAME ---------SMITH WARD SCOTT KING MILLER 5 rows selected. 4. List employees not belonging to department 30, 40, or 10. SQL> select ename from employeess where deptno not in(30,40,10); ENAME ---------SMITH JONES SCOTT ADAMS FORD 5 rows selected. Antesh Kumar Singh Roll No.121379 Page 14
  • 3.
    5. List employeenames for those who have joined between 30 June and 31 Dec. „81. SQL> select ename from employeess where hiredate between '30-june-81' and '31-dec-81'; ENAME ---------MARTIN KING TURNER JAMES FORD 6. List the different designations in the company. SQL> select distinct job from employeess; JOB --------CLERK SALESMAN PRESIDENT MANAGER ANALYST 5 rows selected. 7. List the employees not assigned to any department. SQL> select ename from employeess where job is NULL; no rows selected. 8. List the maximum salary paid to a salesman. SQL> select max(sal) from employeess where job='SALESMAN'; MAX(SAL) ---------1600 Antesh Kumar Singh Roll No.121379 Page 15
  • 4.
    9. List thenames of employees who are not eligible for commission. SQL> select ename from employeess where comm is NULL; ENAME ---------SMITH JONES BLAKE CLARK SCOTT KING ADAMS JAMES FORD MILLER 10 rows selected. 10. List the name and designation of the employee who does not report to anybody. SQL> select ename,job from employeess where job='PRESIDENT'; ENAME JOB ---------- --------- KING PRESIDENT Antesh Kumar Singh Roll No.121379 Page 16
  • 5.
    11. List theemployees who are eligible for commission. SQL> select ename from employeess where job is not NULL; ENAME ---------SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER 14 rows selected. 12. List employees whose names either start or end with “S”. SQL> select ename from emp where ename like 'S%' or ename like '%S'; ENAME ---------SMITH JONES SCOTT Antesh Kumar Singh Roll No.121379 Page 17
  • 6.
    ADAMS JAMES 5 rows selected. 13.List the number of employees working with the company. SQL> select count(ename) from emp; COUNT(ENAME) -----------14 14. List the number of designations available in the EMP table. SQL> select count(distinct job) from emp; COUNT(DISTINCTJOB) -----------------5 15. List the total salaries paid to the employees. SQL> select sum(sal) from emp; SUM(SAL) ---------29025 16. List the maximum, minimum and average salary in the company. SQL> select max(sal), min(sal), avg(sal) from emp; MAX(SAL) MIN(SAL) AVG(SAL) ---------- ---------- ---------- 5000 800 2073.21429 Antesh Kumar Singh Roll No.121379 Page 18