Sample Tables
TABLE : DEPT
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
TABLE : EMP
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 2-Apr-81 2975 20
7654 MARTIN SALESMAN 7698 28-Sep-81 1250 1400 30
7698 BLAKE MANAGER 7839 1-May-81 2850 30
7782 CLARK MANAGER 7839 9-Jun-81 2450 10
7788 SCOTT ANALYST 7566 9-Dec-82 3000 20
7839 KING PRESIDENT 17-Nov-81 5000 10
7844 TURNER SALESMAN 7698 8-Sep-81 1500 0 30
7876 ADAMS CLERK 7788 12-Jan-83 1100 20
7900 JAMES CLERK 7698 3-Dec-81 950 30
7902 FORD ANALYST 7566 3-Dec-81 3000 20
7934 MILLER CLERK 7782 23-Jan-82 1300 10
ASSIGNMENTS ON OPERATORS
1) Display all the employees who are getting 2500 and excess salaries in department 20.
2) Display all the managers working in 20 & 30 department.
3) Display all the managers who don’t have a manager
4) Display all the employees who are getting some commission with their designation is
neither MANANGER nor ANALYST
5) Display all the ANALYSTs whose name doesn’t ends with ‘S’
6) Display all the employees whose naming is having letter ‘E’ as the last but one
character
7) Display all the employees who total salary is more than 2000.
(Total Salary = Sal + Comm)
8) Display all the employees who are getting some commission in department 20 & 30.
9) Display all the managers whose name doesn't start with A & S
10) Display all the employees who earning salary not in the range of 2500 and 5000 in
department 10 & 20.
ASSIGNMENTS ON GROUPING
11) Display job-wise maximum salary.
12) Display the departments that are having more than 3 employees under it.
13) Display job-wise average salaries for the employees whose employee number is not
from 7788 to 7790.
14) Display department-wise total salaries for all the Managers and Analysts, only if the
average salaries for the same is greater than or equal to 3000.
Consider the following table: -
Assignment 5,6,7 & 8 are based on the following table
Table Name : SKILLS
ID Name
101 Oracle
102 Oracle
103 Oracle
101 Oracle
102 Java
103 Java
101 Java
102 Java
103 Java
101 Java
101 Java
101 Oracle
101 VB
102 ASP
15) Select only the duplicate records along-with their count.
16) Select only the non-duplicate records.
17) Select only the duplicate records that are duplicated only once.
18) Select only the duplicate records that are not having the id=101.
ASSIGNMENTS ON FUNCTIONS
19) Without Using the LAST_DAY function, write the query for the following.
I. Get the First Day of the next month.
II. Get the Last Day of the next month.
III. Get the First Day of the current month.
IV. Get the Last Day of the current month.
V. Get the First Day of the previous month.
VI. Get the Last Day of the previous month.
20) Write a query to display the date in the following formats: -
I. 2000-16-08 23:10:10
II. 09 AM
21) Write a query to find date on next to next SUNDAY.
22) Write a query that returns a date, which is exactly 3 years from now.
23) Write a query that returns a date, which is exactly 1 year before as of today.
24) Write a query to round off the given number as shown below: -
Given Numbers Rounded-off
Number
1879.989 1879.99
1879.989 1880
1879.989 1900
1879.989 2000
25) Display the employees who are completed 20 years in the company as of today.
26) Display the Employee Names, salary and the day in which they have joined the
company.
27) Display the output as follows: -
SMITH working in Dept 20 is earning salary of 200 with commission of 0.
ALLEN working in Dept 30 is earning salary of 1600 with commission of 300
etc…
NOTE: - If the commission is NULL, it should be displayed as zero.
28) Write a query that adds 25 seconds to the current time.
29) Can DECODE function also be used as a NVL function? Give an example.
30) Get all the employees whose name is having more than 5 characters.
31) Display all the employees who have joined the company in the year 1980.
32) Write a query to find out how many times 'L' has occurred in “SQL CLASSES”.
33) Write a query to swap the first name and last name.
Table Name : PLAYERS Column Name : NAME
ASSIGNMENTS ON SUBQUERIES
34) Display all the employees who are earning more than all the managers.
35) Display all the employees who are earning more than any of the managers.
36) Select employee number, job & salaries of all the Analysts who are earning more than
any of the managers.
37) Select all the employees who work in DALLAS.
38) Select department name & location of all the employees working for CLARK.
39) Select all the departmental information for all the managers
40) Display the first maximum salary.
41) Display the second maximum salary.
42) Display the third maximum salary.
43) Display all the managers & clerks who work in Accounts and Marketing departments.
44) Display all the salesmen who are not located at DALLAS.
45) Get all the employees who work in the same departments as of SCOTT.
46) Select all the employees who are earning same as SMITH.
47) Display all the employees who are getting some commission in marketing department
where the employees have joined only on weekdays.
48) Display all the employees who are getting more than the average salaries of all the
employees.
ASSIGNMENTS ON JOINS
ASSIGNMENTS ON EQUI-JOINS
49) Display all the managers & clerks who work in Accounts and Marketing departments.
50) Display all the salesmen who are not located at DALLAS.
51) Select department name & location of all the employees working for CLARK.
52) Select all the departmental information for all the managers
53) Select all the employees who work in DALLAS.
54) Delete the records from the DEPT table that don’t have matching records in EMP
ASSIGNMENTS ON OUTER-JOINS
55) Display all the departmental information for all the existing employees and if a
department has no employees display it as “No employees”.
56) Get all the matching & non-matching records from both the tables.
57) Get only the non-matching records from DEPT table (matching records shouldn’t be
selected).
58) Select all the employees name along with their manager names, and if an employee
does not have a manager, display him as “CEO”.
ASSIGNMENTS ON SELF-JOINS
59) Get all the employees who work in the same departments as of SCOTT
60) Display all the employees who have joined before their managers.
61) List all the employees who are earning more than their managers.
62) Fetch all the employees who are earning same salaries.
63) Select all the employees who are earning same as SMITH.
64) Display employee name , his date of joining, his manager name & his manager's date
of joining.
ASSIGNMENTS ON CORRELATED SUBQUERIES
65) Write a query to get 4th max salary from EMP table
66) Write a query to get 2nd & 6th max salary from EMP table
67) Write a query to get first 3 salaries from the EMP table
68) Write a query to get 2nd least salary from the EMP table
69) Write a query to get least 3 salaries from the EMP table
70) List all the employees whose salaries are greater than their respective departmental
average salary.