SQL HR Case Study
SQL HR Case Study
1. Display the first name and department number for all customers whose last name is “De Haan”
(Employees table).
2. Display all data from Departments table for Sales department (department_name column).
3. Display the first name, last_name, department number and salary for all employees who earn
more than 9700 (Employees table).
4. Display all data from Employees table for all employees who was hired before January 1st, 1992.
5. Display the employee number, first name, job id and department number for all employees whose
department number equals 20, 60 or 80 (Employees table).
6. Display the employee number, first name, job id and department number for all employees whose
department number is not equal to 20, 60 and 80 (Employees table).
7. Display the last name, phone number, salary and manager number, for all employees whose
manager number equals 100, 102 or 103 (Employees table).
8. Display the first name and salary for all employees whose first name ends with an e (Employees
table).
9. Display the last name and department number for all employees where the second letter in their
last name is i (Employees table).
10. Display all data from Employees table for all employees who have the letters : L, J, or H in their
last name. Sort the query in descending order by salary.
11. Display the first name, hire date, salary and department number for all employees whose first
name doesn’t have the letter A. Sort the query in ascending order by department number
(Employees table).
12. Display all data from Employees table for all employees without any department number.
13. Display the first name concatenated with the last name, separated by comma, and salary, for all
employees whose salary not in the range between 7000 and 15000. Sort the query in ascending
order by the full name (Employees table).
14. Display the first name concatenated with the last name, separated by comma, the phone
number concatenated with the email address, separated by hyphen, and salary, for all employees
whose salary is in the range of 5000 and 10000. Name the column headings: “FULL_NAME”,
“CONTACTS” and “SAL” respectively (Employees table).
15. Display all data from Employees table for all employees whose: salary is in the range of 6000 and
800 and their commission is not null or department number is not equal to 80, 90 and 100 and their
hire date is before January 1st, 1990.
16. Display last name, job id and hire date for all employees who was hired during December 12th,
1995 and April 17th, 1998.
17. Display the first name concatenated with last name, hire date, commission percentage,
telephone, and salary for all employees whose salary is greater than 10000 or the third digit in their
phone number equals 5. Sort the query in a descending order by the first name (Employees table).
18. Display the last name and salary for all employees who earn more than 12000 (Employees table).
19. Display the last name and department number for all employees whose department number is
equal to 50 or 80. Perform this exercise once by using the IN operator, once by using the OR
operator.
20. Display the first name and salary for all employees who doesn’t earn any commission.
21. Display the first name, salary, and manager number for all employees whose manager number is
not null
1. Display the first name in lower case and last name in upper case, for all employees whose
employee number is in the range between 80 and 150.
2. Display the first name and last name for all employees whose family name is King, perform this
exercise with a case-insensitive search (regardless of the capitalization used for the values within last
name column).
a. For each employee, display the first name, last name, and email address. The email
address will be composed from the first letter of first name, concatenated with the three
first letters of last name, concatenated with @oracle.com.
b. For each employee, display the first name, last name, and email address. The email
address will be composed from the first letter of first name, concatenated with the three last
letters of last name, concatenated with @oracle.com.
a. For each employee, use the CONCAT function to display the first name concatenated with
the last name.
b. For each employee, use the CONCAT function to display the first name concatenated with
the last name, concatenated with hire date.
5. Display the last name for all employees where last name’s length is greater than 8 characters.
6. Phone numbers:
a. For each employee, display the first name, last name, phone number and a new phone
number using the REPLACE function. in the new phone number replace all occurrences of
515 with 815.
b. For each employee, display the first name, last name, phone number and a new phone
number using the REPLACE function. in the new phone number replace all prefixes of 515
with 815.
b. salary
e. salary after a raise of 12%, round down to the nearest whole number.
8. For each employee, display the first name, hire date, hire date minus 10 days, hire date plus one
month, and the day difference between current date and hire date.
9. For each employee, display the first name, last name, hire date, number of months he works in
the company, and number of years he works in the company.
10. For each employee, display the first name, hire date, and hire date plus one year.
11. For each employee, display the first name, hire date, hire date rounded up to the nearest year,
and hire date rounded up to the nearest month.
12. For each employee, display the first name, the day of his hire date, and the year of his hire date.
13. Display the last name in upper case, the salary in format model : ‘9,999.999’, and hire date in
format model: ‘DD/MM/YYYY’, for all employees whose last name begins with the letter D or K.
a. For each employee, display the first name, last name, salary and commission percentage.
If an employee doesn’t earn a commission, display 0 instead of NULL.
b. For each employee, display the first name, last name, salary and commission percentage.
If an employee doesn’t earn a commission, display “No Commission” instead of NULL.
15. For each employee, display the first name, last name, salary, and a salary grade based on these
conditions :
1.Create a query to display the employee number, first name, last name, phone number and
department number (Employees table).
2. Create a query to display the first name, last name, hire date, salary, and salary after a raise of
20%. Name the last column (salary after a raise) heading as “ANNUAL_SAL” (Employees table).
3. Create a query to display the last name concatenated with the first name, separated by space, and
the telephone number concatenated with the email address, separated by hyphen. Name the
column headings “FULL_NAME” and “CONTACT_DETAILS” respectively (Employees tables).
4. Create a query to display the unique manager numbers from Employees table.
5. Create a query to display the last name concatenated with job_id column, separated by space.
Name this column heading as “EMPLOYEE_AND_TITLE” (Employees table).
6. Create a query to display the first name, last name, salary, and hire date concatenated with the
literal string “HD”, separated by space. Name the column headings “FN”, “LN”, “SAL”, and “HD”
respectively (Employees table).
8. Create a query to display the unique combination of values in department_id and job_id columns
(Employees table)
4. Display the number of values (exclude NULLs) in commission_pct column (Employees table).
7. Average salary per department a. Display the department number and average salary for each
department. b. Modify your query to display the results only for departments 50 or 80.
a. Display the job id and the number of employees for each job id.
b. Modify your query to display the results only for employees whose salary is greater the
10000.
c. Modify your query again, this time display the results only for jobs with more than 2
people.
9. Display the department number, job id, and the average salary for each department and job id.
10. Managers and highest salary a. Display the manager number and the highest salary for each
manager number. b. Modify your query to display the results only for employees whose salary is
greater than 10000.
11. Display the job id and minimum salary for each job id, for all jobs whose minimum salary is
greater than 7000.
12. Display the department number, and the average salary for each department, for all
departments whose number is in the range of 20 and 80, and their average salary is greater than
9000
2. Display the department number and department name for all departments whose location
number is equal to the location number of department number 90 (Departments table).
3. Display the last name and hire date for all employees who was hired after employee number 101
(Employees table).
4. Display the first name, last name, and department number for all employees who work in Sales
department (Employees and Departments table).
5. Display the department number and department name for all departments located in Toronto
(Departments table).
6. Display the first name, salary and department number for all employees who work in the
department as employee number 124 (Employees table).
7. Display the first name, salary, and department number for all employees who earn more than the
average salary (Employees table).
8. Display the first name, salary, and department number for all employees whose salary equals one
of the salaries in department number 20 (Employees table).
9. Display the first name, salary, and department number for all employees who earn more than
maximum salary in department number 50 (Employees table).
10. Display the first name, salary, and department number for all employees who earn more than
the minimum salary in department number 60 (Employees table).
11. Display the first name, salary, and department number for all employees who earn less than the
minimum salary of department number 90 (Employees table).
12. Display the first name, salary and department number for all employees whose department is
located Seattle (Employees, Departments and Locations table).
13. Display the first name, salary, and department number for all employees who earn less than the
average salary, and also work at the same department as employee whose first name is Kevin
a. For each employee, display the first name, last name, department number and department name.
b. Display the first name, last name, department number and department name, for all employees in
departments 50 or 90.
a. For each department, display the department name, city, and state province.
b. For each employee, display the full name, department name, city, and state province.
c. Display the full name, department name, city, and state province, for all employees whose last
name contains the letter a.
a. Display the first name, last name, department number and department name, for all employees
including those without any department.
b. Modify your query to display all departments including departments without any employees.
a. For each employee, display the last name, and the manager’s last name.
b. Modify your query to display all employees including those without any manager.
6. Display the first name, last name, and department number for all employees who work in the
same department as employee whose last name is “King”.
7. Display the last name and salary for all employees who earn less than employee number 103