Assignmet HR MySql
Assignmet HR MySql
-------------------------------------------
The HR department needs your assistance in creating some queries.
1. Because of budget issues, the HR department needs a report that displays the
last name and salary of employees earning more than $12,000.
2. Open a new SQL Worksheet. Create a report that displays the last name and
department number for employee number 176.
4. Modify above query to list the last name and salary of employees who earn
between $5,000 and $12,000, and are in department 20 or 50. Label the columns
Employee and Monthly Salary,
respectively.
5. Modify lab_03_03.sql to list the last name and salary of employees who earn
between $5,000 and $12,000, and are in department 20 or 50. Label the columns
Employee and Monthly Salary,
respectively.
6. Create a report to display the last name, job ID, and hire date for employees
with the last names of Matos and Taylor. Order the query in ascending order by hire
date.
8. The HR department needs a report that displays the last name and hire date of
all employees who were hired in 2006.
9. Create a report to display the last name and job title of all employees who do
not have a manager.
10. Create a report to display the last name, salary, and commission for all
employees who earn commissions. Sort data in descending order of salary and
commissions.
Use the column’s numeric position in the ORDER BY clause.
11. Display the last names of all employees where the third letter of the name is
“a.”
12. Display the last names of all employees who have both an “a” and an “e” in
their last name.
13. Display the last name, job, and salary for all employees whose job is that of a
sales representative or a stock clerk, and whose salary is not equal to $2,500,
$3,500, or $7,000.
14. Display the last name, salary, and commission for all employees whose
commission amount is 20%.
2. Create a query that displays 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.
------------------------------------------------ Joins
--------------------------------------------------------
1. Write a query for the HR department to produce the addresses of all the
departments. Use the LOCATIONS and COUNTRIES tables. Show the location ID, street
address, city, state or
province, and country in the output.
3. The HR department needs a report of employees in Toronto. Display the last name,
job, department number, and department name for all employees who work in Toronto.
4. Create a report to display employees’ last names and employee numbers along with
their managers’ last names and manager numbers. Label the columns Employee, Emp#,
Manager, and Mgr#,
respectively.
5. Modify above to display all employees, including King, who has no manager. Order
the results by employee number.
6. Create a report for the HR department that displays employee last names,
department numbers, and all employees who work in the same department as a given
employee. Give each column an
appropriate label. Save the script to a file named lab_07_06.sql. Run the query.
8. The HR department wants to determine the names of all employees who were hired
after Davies. Create a query to display the name and hire date of any employee
hired after employee
Davies.
9. The HR department needs to find the names and hire dates of all employees who
were hired before their managers, along with their managers’ names and hire dates.
1. The HR department needs a query the to display the last name and hire date of
any employee in the same department as the employee whose name the user supplies
(excluding that
employee). For example, if the user enters Zlotkey, find all employees who work
with Zlotkey (excluding Zlotkey).
2. Create a report that displays the employee number, last name, and salary of all
employees who earn more than the average salary. Sort the results in ascending
order by salary.
3. Write a query that displays the employee number and last name of all employees
who work in a department with any employee whose last name contains the letter “u.”
4. The HR department needs a report that displays the last name, department number,
and job ID of all employees whose department location ID is 1700.
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
the salary of any employee from department 60.
8. Modify above query in display the employee number, last name, and salary of all
employees who earn more than the average salary and who work in a department with
any employee whose
last name contains the letter “u.”
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 in
them. Display the country IDs and the names of the countries. Use the set operators
to create this
report.
3. Produce a list of all the employees who work in departments 50 and 80. Display
the employee ID, job ID, and department ID by using the set operators.
4. Create a report that lists the detail of all employees who are sales
representatives and are currently working in the sales department.
2.Create an INSERT statement to add the first row of data to the MY_EMPLOYEE table
from the following sample data. Do not list the columns in the INSERT clause.
3. Populate the MY_EMPLOYEE table with the second row of the sample data from the
preceding list. This time, list the columns explicitly in the INSERT clause.
5. Change the salary to $1,000 for all employees with a salary less than $900.
5. Promote Employee
Objective: Create a stored procedure to promote an employee by changing their job
title and salary.
Input: p_employee_id IN NUMBER, p_new_job_id IN VARCHAR2, p_salary_increase IN
NUMBER
Output: Success or failure message.
Business Logic: The procedure should check if the employee exists, and then update
the job_id and salary based on the provided values. Ensure salary increase is not
less than a certain percentage (e.g., 10%).
DELIMITER $$
7. Employee Tenure
Objective: Create a stored procedure that calculates and returns the tenure (in
years) for an employee based on their hire date.
Input: p_employee_id IN NUMBER
Output: Employee's tenure in years.
Business Logic: The procedure should calculate the difference between the current
date and the employee's hire date, returning the number of years the employee has
worked.