12
1) List all the employees working in departments present in location 'NEW YORK', 'BANGALORE' using sub query. Use table EMP and DEPT 2) Using sub query, Display employee name, job, hire date, salary from EMP table who is not a clerk and salary is less than the maximum salary of a clerk order employee names in alphabetical order. 3) Explain the use of Exists operator using an example of sub query. 4) Is the below mentioned query correct. If no then please correct the query. Select * From Emp Where Mgr = ( Select Empno From Emp Where Job = 'MANAGER' ) 5) Give an example of correlated sub query. 6) Using sub query, List the name of all departments which is having an average salary less than the average salary of 'ACCOUNTING' department. Use table EMP and DEPT. 7) List the name, job and salary of all employees having fifth highest salary using EMP table. 8) Use EMP table, list the Employee number, Name & Job of all employees working under employee ‘FORD’ using sub query. 9) Explain the use of ‘ANY’ operator using sub query. 10) Use EMP table, list employee name, job, salary and manager name of the employee having salary less than the salary of a 'SALESMAN'

Assignments 3

Embed Size (px)

Citation preview

Page 1: Assignments 3

1) List all the employees working in departments present in location 'NEW YORK', 'BANGALORE' using sub query. Use table EMP and DEPT

2) Using sub query, Display employee name, job, hire date, salary from EMP table who is not a clerk and salary is less than the maximum salary of a clerk order employee names in alphabetical order.

3) Explain the use of Exists operator using an example of sub query.

4) Is the below mentioned query correct. If no then please correct the query.

Select * From Emp Where Mgr = (Select Empno From Emp Where Job = 'MANAGER')

5) Give an example of correlated sub query.

6) Using sub query, List the name of all departments which is having an average salary less than the average salary of 'ACCOUNTING' department. Use table EMP and DEPT.

7) List the name, job and salary of all employees having fifth highest salary using EMP table.

8) Use EMP table, list the Employee number, Name & Job of all employees working under employee ‘FORD’ using sub query.

9) Explain the use of ‘ANY’ operator using sub query.

10) Use EMP table, list employee name, job, salary and manager name of the employee having salary less than the salary of a 'SALESMAN'

11) Write a sub query using table Employee and Dependent to list the name of employees having one female child.

12) Write a query to generate output in the format given below using EMP and DEPT tables. X-Axis data represents departments, Y-Axis represents cities and cell value represents number for employees working in each department of the city.

Page 2: Assignments 3

13) Using EMP table, write a query to list all the employees who joined before there managers joined and after the “PRESIDENT” joined.

14) Using EMP table, write a query to find the name of employee who joined first.

15) Using EMP table, find the name of employee who has worked in more than two departments.

16) Using EMP table, find the name of employee not working under “PRESIDENT” and salary is less than the average salary of a “CLERK”

17) Using sub query, display list of departments name and number of people working in each department and staying in “Houston”. Use tables Department and Employee

18) Using EMP table, find the name, job and hire date of employees where more than one people joined on the same day.

19) Using sub query, list all the department names and sum of salary department wise. 20) Using sub query, list all the employees who earn salary more than there manager.

1) Using SQL Plus, write a query to list all the employees from EMP table with job as input parameter.

2) Using SQL Plus, write a query to list all the employees from EMP table with where clause as input parameter.

3) Using SQL Plus, write a query to list all the records from table. Use input parameters for table name and where clause.

4) Using SQL Plus, write a query to list all the EMP NO, ENAME, JOB and SALARY from EMP table with order by clause as input parameter.

5) Explain the use of double amberscent (i.e. &) in SQL Plus. Explain with an example.

6) Explain the use of DEFINE and UNDEFINE commands with an example.7) How do you display value of a variable before and after it is being changed in

SQL Plus.8) Using SQL Plus, write a query to list fname, lname and salary from employees

table in the format given below.

9) Using SQL Plus, write a query to list employee name , department name, location from dept table with department name truncated to 4 characters as shown below.

Page 3: Assignments 3

11) Using SQL Plus, write a query to list job, employee number & name from emp table with job displayed only once for the employees. Output should be as shown below.

10) Using EMP table, generate output as shown below.

16) Using EMP table, generate output in the format given below. Note:- where ever mgr field is null it should display as ‘No Manager’

17) Explain the use of “SET VERIFY ON” command.18) Explain with an example how to enforce leading zeros to a number field.20) Using EMP table, generate output in the format given below.

Page 4: Assignments 3

1) SQL statements containing these set operators are referred to as

a. compound queries b. Set Queriesc. Union Queriesd. Select Statement

2) Two SELECTs can be combined into a compound query by a set operation only if they satisfy the two conditions.

a. The result sets of both the queries must have the ______ number of columns.

b. The ______ of each column in the second result set must match the datatype of its corresponding column in the first result set

Note: The datatypes do not need to be the same if those in the second result set can be automatically converted by Oracle (using implicit casting) to types compatible with those in the first result set.

3) Operators used to combine the results from two or more SELECT statements is named as _________

4) List all the SET OPERATORS which Oracle Provided. Give and example of each with description

5) If we want to use ORDER BY in a query involving set operations, we must place the ORDER BY at the __________ of the entire statement.

6) How many times ORDER BY clause can be used in Select Query7) Give generic syntax of a query involving a set operation8) UNION ALL ______ the results of two SELECT statements into ______

result set. 9) _____ Returns only those rows that are returned by each of two SELECT

statements10) _____ Combines the results of two SELECT statements into ____ result set,

and then eliminates any duplicate rows from that result set.11) ______ Takes the result set of one SELECT statement, and removes those

rows that are also returned by a second SELECT statement.12) For below question System should not be used. (Ans should by given only

after Dry RUN)

EMP_TABLEENAME DEPTNO SAL

Page 5: Assignments 3

E1 D1 10000E2 D2 10000E4 D3 10000E5 D1 20000E3 D3 3000E6 D2 40000

DEPT_TABLEDEPTNO DEPT_NAME LOCIDD1 Deptno1 L1D2 Deptno2 L2D3 Deptno3 L3D4 Deptno4 L4

What will be the result if someone executes?a) Select Deptno From EMP_TABLE Union Select Deptno From DEPT_TABLE

b) Select Deptno From EMP_TABLE Union All Select Deptno From DEPT_TABLE

c) Select Deptno From EMP_TABLE Minus Select Deptno From DEPT_TABLE

d) Select Deptno From DEPT_TABLE Minus Select Deptno From EMP_TABLE

e) Select Deptno From DEPT_TABLE Intersect Select Deptno From EMP_TABLE

f) Select Deptno,Sal From EMP_TABLE Intersect Select Deptno, LocID From DEPT_TABLE

Page 6: Assignments 3

g) Select Deptno,'' LocID From EMP_TABLE Intersect Select Deptno, LocID From DEPT_TABLE

h) Select Deptno, LocID From DEPT_TABLE Union Select Deptno,'' LocID From EMP_TABLENote: No System help required for the above question

13) Use above table and tell the answer (NO System required….Use Paper and execute by yourself)

Select E.Deptno From (Select Deptno, LocID From DEPT_TABLE Union Select Deptno,'' LocID From EMP_TABLE) EIntersect Select D.Deptno

From DEPT_TABLE D

14) Use above table data and tell the answer

Select * From EMP_TABLE Where DEPTNO NOT IN (Select E.Deptno From (Select Deptno, LocID From DEPT_TABLE Union Select Deptno,'' LocID From EMP_TABLE) EIntersect Select D.Deptno From DEPT_TABLE D)

15) Give output of below querySelect Deptno, LocID From DEPT_TABLE Order By LocID Union Select Deptno,'' LocID From EMP_TABLE Order By DEPTNo

16) Tell the execution hierarchy of below query

SELECT * FROM SUPPLIER_GOODUNION(SELECT * FROM SUPPLIER_TESTMINUSSELECT * FROM SUPPLIER);

41. Write a query to display the last name and hire date of any employee in the same

Page 7: Assignments 3

department as Zlotkey. Exclude Zlotkey.(last name is Zlotkey)

42. Create a query to display the employee numbers and last names of all employees who earn more than the average salary. Sort the results in descending order of salary.

43. Write a query that displays the employee numbers and last names of all employees who work in a department with any employee whose last name contains a ‘u’.

44. Display the last name, department number, and job ID of all employees whose department location ID is 2700.

45. Display the last name and salary of every employee who reports to King.

46. Display the department number, last name, and job ID for every employee in the Executive department.

47. Display the employee numbers, last names, and salaries of all employees who earn more than the average salary and who work in a department with any employee with a u in their name.

48. Write a query to display the last name, department number,and salary of any employee who earns a commission.

49. Display the last name, department name and salary of any employee whose salary and commission match the salary and commission of any employee located in location id 1700.

50. Create a query to display the last name, hire date and salary for all employees who have the same salary and commission as Kochhar.

51. Create a query to display the employees who earn a salary greater the salary of all the sales managers(SA_MAN).Sort the results on salary from highest to lowest.

52.Display the details of the employee id, last name and department id of those employees who live in cities whose name begin with ‘T’.

53. Write a query to find all employees who earn more than the average salary in their departments. Display last name, salary ,department id and the average salary for the department. Sort by average salary. Use aliases for the columns retrieved by the query.

54. Find all employees who are not supervisors using NOT EXISTS Operator

55. Write a query to display the last names of the employees who have one or more co workers in their departments with later hire dates but higher salaries.

56. Write a query to display the department names of those departments whose total salary is above (1/8) of the total salary cost to the whole company. Name the query as summary.

57. Show the department number and the lowest salary of the department with the highest average salary.

Page 8: Assignments 3

58. Show the department numbers, names, and locations of the departments where no sales representatives work(SA_REP)

59. Write a query to display the top three earners in the employees table. Display their last names and salaries.

60. Write a query to display the employee id and last names of the employees who work in the state of California.

1. The HR department needs a query that prompts the user for an employee last name. The query then displays the last name and hire date of any employee in the same department as the employee whose name they supply (excluding that employee).

2) Create a report that displays the employee number, last name, and salary of allemployees who earn more than the average salary. Sort the results in order ofascending salary

5) Create a report for HR that displays the last name and salary of every employee who reports to King.

6) Create a report for HR that displays the department number, last name, and job ID for every employee in the Executive department

7) Create a report that displays a list of all employees whose salary is more than thesalary of any employee from department 60.

1. The HR department needs a list of department IDs for departments that do not contain the job ID ST_CLERK. Use the set operators to create this report.

2) The HR department needs a list of countries that have no departments located inthem. Display the country ID and the name of the countries. Use the set operators tocreate this report.

3) Produce a list of jobs for departments 10, 50, and 20, in that order. Display the job ID and department ID by using the set operators.

4) Create a report that lists the employee IDs and job IDs of those employees whocurrently have a job title that is the same as their job title when they were initiallyhired by the company (that is, they changed jobs, but have now gone back to doingtheir original job).

5) The HR department needs a report with the following specifications:• Last name and department ID of all employees from the EMPLOYEES table,regardless of whether or not they belong to a department• Department ID and department name of all departments from the DEPARTMENTStable, regardless of whether or not they have employees working in themWrite a compound query to accomplish this.