Sie sind auf Seite 1von 2

SQL Assignments

EMP Table Structure:

Name Null? Type


------------------------------- -------- ----------------------
EMPNO NOT NULL NUMBER(4), Primary Key
ENAME VARCHAR2(10)
JOB VARCHAR2(9)
MGR NUMBER(4), may/may not any EMPNO
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER(2) foreign key of DEPT table

Records in EMP Table

EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO


--------- ---------- --------- --------- --------- --------- --------- --------- ------------ --------------
7369 SMITH CLERK 7902 17-DEC-80 800 20
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 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10

DEPT Table Structure:

Name Null? Type


------------------------------- -------- ----
DEPTNO NOT NULL NUMBER(2), Primary key
DNAME VARCHAR2(14)
LOC VARCHAR2(13)

Records in DEPT Table:

DEPTNO DNAME LOC


--------- -------------- -------------
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
Assignment # 01

1. Display the name, deptno, dname for all employees.


2. Create a unique listing of all jobs that are in deptno 30. Include the location of dept 30 in the output.
3. Display the employee name, dept name and the location of all employees who earn a commission.
4. Display the employee name, dept name for all employees who have an ‘A’ in their name.
5. Display the employee name, job, deptno, dept name for all employees who work in DALLAS.
6. Display the employee name, empno along with their manager’s name and manager no.
7. Modify query 6 to display all employees including king, who has no manager.
8. Display the employee name of all the employees that work in the same deptno as a given employee.
9. Display the employee name, job, dept name, salary and grade for all employees.
10. Display the employee name, and hire date of any employee hired after BLAKE.
11. Display the employee name, and hire date along with their manager’s name and hire date of all employees
hired before their manager.
12. Find the second highest salary from emp table.

Assignment #02

1. List the names of analysts and salesmen.


2. List details of employees who have joined before 30 Sep 81.
3. List names of employees who are not managers.
4. List the names of employees whose employee numbers are 7369, 7521, 7839,
7934, 7788.
5. List employees not belonging to department 30, 40, or 10.
6. List employee names for those who have joined between 30 June and 31 Dec. „81.
7. List the different designations in the company.
8. List the names of employees who are not eligible for commission.
9. List the name and designation of the employee who does not report to anybody.
10. List the employees not assigned to any department.
11. List the employees who are eligible for commission.
12. List employees whose names either start or end with “S”.
13. List names of employees whose names have “i” as the second character.
14. List the number of employees working with the company.
15. List the number of designations available in the EMP table.
16. List the total salaries paid to the employees.
17. List the maximum, minimum and average salary in the company.
18. List the maximum salary paid to a salesman.

Assignment #03

1) List the number of employees and average salary for employees in department 20.
2) List name, salary and PF amount of all employees. (PF is calculated as 10% of
basic salary)
3) List names of employees who are more than 2 years old in the company.
4) List the employee details in the ascending order of their basic salary.
5) List the employee name and hire date in the descending order of the hire date.
6) List employee name, salary, PF, HRA, DA and gross; order the results in the
ascending order of gross. HRA is 50% of the salary and DA is 30% of the salary.
7) List the department numbers and number of employees in each department.
8) List the department number and total salary payable in each department.
9) List the jobs and number of employees in each job. The result should be in the
descending order of the number of employees.
10) List the total salary, maximum and minimum salary and average salary of the
employees jobwise.
11) List the total salary, maximum and minimum salary and average salary of the
employees, for department 20.
12) List the total salary, maximum and minimum salary and average salary of the
employees jobwise, for department 20 and display only those rows having an
average salary > 1000

Das könnte Ihnen auch gefallen