SQL Assignements
SQL Assignements
TABLE : DEPT
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
TABLE : EMP
ASSIGNMENTS ON OPERATORS
1) Display all the employees who are getting 2500 and excess salaries in department 20.
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
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.
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
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.
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: -
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.
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.
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.
38) Select department name & location of all the employees working for CLARK.
39) Select all the departmental information for all the managers
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
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.
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.