sql task

7
Human Resources ( HR ) This is the schema that is used in this course. In the Human Resource (HR) records, each employee has an identification number, email address, job identification code, salary, and manager. Some employees earn commissions in addition to their salary. The company also tracks information about jobs within the organization. Each job has an identification code, job title, and a minimum and maximum salary range for the job. Some employees have been with the company for a long time and have held different positions within the company. When an employee resigns, the duration the employee was working for, the job identification number, and the department are recorded. The sample company is regionally diverse, so it tracks the locations of its warehouses and departments. Each employee is assigned to a department, and each department is identified either by a unique department number or a short name. Each department is associated with one location, and each location has a full address that includes the street name, postal code, city, state or province, and the country code. In places where the departments and warehouses are located, the company records details such as the country name, currency symbol, currency name, and the region where the country is located geographically.

Upload: nawaz-sk

Post on 20-Jan-2015

711 views

Category:

Education


2 download

DESCRIPTION

Sql task

TRANSCRIPT

Page 1: Sql task

Human Resources ( HR ) This is the schema that is used in this course. In the Human Resource (HR) records, each employeehas an identification number, email address, job identification code, salary, and manager. Someemployees earn commissions in addition to their salary.The company also tracks information about jobs within the organization. Each job has anidentification code, job title, and a minimum and maximum salary range for the job. Someemployees have been with the company for a long time and have held different positions within thecompany. When an employee resigns, the duration the employee was working for, the jobidentification number, and the department are recorded.The sample company is regionally diverse, so it tracks the locations of its warehouses anddepartments. Each employee is assigned to a department, and each department is identified either by a unique department number or a short name. Each department is associated with one location, and each location has a full address that includes the street name, postal code, city, state or province, and the country code.In places where the departments and warehouses are located, the company records details such as the country name, currency symbol, currency name, and the region where the country is locatedgeographically.

Page 2: Sql task

HR Schema:

COUNTRIESDEPARTMENTSEMPLOYEESJOB_GRADESJOB_HISTORYJOBSLOCATIONSREGIONS

Task:

1)Write a query that displays the last name (with the first letter in uppercase and all the other letters in lowercase) and the length of the last name for all employees whose name starts with the letters “J,” “A,” or “M.” (Use Employees table)

2)Write a query which will print the employees last_name, no.of months worked till date and their manager name.Label the columns with the following: Employee – Experience in months – Manager Id

3)Create a query that displays the first eight characters of the employees’ last names and indicates the amounts of their salaries with asterisks. Each asterisk signifies a thousand dollars. Sort the data in descending order of salary. Label the column EMPLOYEES_AND_THEIR_SALARIES.

4)Create a query to display the last name and the number of weeks employed for allemployees in department 90. Label the number of weeks column TENURE. Truncatethe number of weeks value to 0 decimal places. Show the records in descending orderof the employee’s tenure.

Page 3: Sql task

5)Display each employee’s last name, hire date, and salary review date, which is the first Monday after six months of service. Label the column REVIEW. Format the dates to appear in the format similar to “Monday, the Thirty-First of July, 2000.”

6)Create a report to display the manager number and the salary of the lowest-paidemployee for that manager. Exclude anyone whose manager is not known. Excludeany groups where the minimum salary is $6,000 or less. Sort the output in descendingorder of salary.

7)Create a query to display the total number of employees and, of that total, the numberof employees hired in 1995, 1996, 1997, and 1998. Create appropriate columnheadings.

8)Create a matrix query to display the job, the salary for that job based on departmentnumber, and the total salary for that job, for departments 20, 50, 80, and 90, givingeach column an appropriate heading.

Page 4: Sql task

9)Create a query that displays the employee last name, job title, department name, salary, and grade for all employees. (Tables to be used Employees, Departments, Jobs)

10)Write a query to find the names and hire dates of all the employees who were hired before their managers, along with their managers’ names and hire dates.

11)Write a query that displays the employee number and last name of all employees whowork in a department with any employee whose last name contains the letter “u.”

Page 5: Sql task

12)Create a table MY_EMPLOYEE which is a replicate of 'EMPLOYEES' table with all the data.

13)Add a new column USER_ID to MY_EMPLOYEE table and enforce a unique constraint.

14)Update the USER_ID column of MY_EMPLOYEE table with the following format.user_id should contain first letter of the last_name concatenated with first_name of the employee and the maximum length of the user_id should be 8.

15)Change the salary to $1,000 for all employees who have a salary less than $900 in MY_EMPLOYEE table.

16)Create a view named DEPT50 that contains the employee numbers, employee last names, and department numbers for all employees in department 50. Label the view columns EMPNO, EMPLOYEE, and DEPTNO. For security purposes, do not allow an employee to be reassigned to another department through the view.

17)Show all employees who were hired on the day of the week on which the highest number of employees were hired.

18)Write a query to get the nth highest salary among the employees.Query should accept a value for n.If n = 2, then it should retrieve all the employee names who are earning 2nd highest salary among the employees.

19)Suppose the primary key constraint has been disabled on employee_id column and users have entered duplicate employee_id's within the employee table.Write a query to remove the duplicate rows from the table and preserve the original employee_id which was existing.