Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
146 views2 pages

SQL Queries for HR Database Tasks

This document contains 7 SQL queries that were written as part of a database lab exercise. The queries retrieve employee data from the employees table for various reports and analyses. They include queries to display the system date, calculate salary increases, subtract old and new salaries, filter employee names by starting letter, prompt the user to enter a starting letter, calculate months of employment, and more. The queries make use of functions like SYSDATE, ROUND, INITCAP, SUBSTR, and MONTHS_BETWEEN to manipulate and retrieve the desired data fields.

Uploaded by

aqilah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
146 views2 pages

SQL Queries for HR Database Tasks

This document contains 7 SQL queries that were written as part of a database lab exercise. The queries retrieve employee data from the employees table for various reports and analyses. They include queries to display the system date, calculate salary increases, subtract old and new salaries, filter employee names by starting letter, prompt the user to enter a starting letter, calculate months of employment, and more. The queries make use of functions like SYSDATE, ROUND, INITCAP, SUBSTR, and MONTHS_BETWEEN to manipulate and retrieve the desired data fields.

Uploaded by

aqilah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CISB214 – Database 1

Lab Exercise 3
Aqilah Nadhirah Binti Mohd Ashri (IS0106002)
Nur Syarah Ilya Binti Nasari (IS0106019)

1. ​ ​Write a query to display the system date. Label the column Date.
SELECT sysdate “Date”
FROM dual;

2. The HR department needs a report to display the employee number, last name, salary
and salary increased by 15.5% (expressed as a whole number) for each employee. Label
the column New Salary.

SELECT employee_id, last_name, salary,


ROUND (salary *1.155, 0) “New Salary”
FROM employees;

3. Modify the query in question (2) to add a column that subtracts the old salary from the
new salary. Label the column Increase.

SELECT employee_id, last_name, salary,


ROUND (salary * 1.155,0) “New Salary”
ROUND (salary * 1.155,0) – salary “Increase”
FROM employees;

4. 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 letter “J”, “A”, or “M”. Give each column an appropriate label. Sort the
results by the employees’ last names.

SELECT INITCAP (lastname), LENGTH (last_name)


FROM employees
WHERE SUBSTR (last_name, 0,1) IN (‘J’,’M’,’A’)
ORDER BY last_name;

5. Rewrite the query in question (4) so that the user is prompted to enter a letter that the
last name starts with. For example, if the user enters “H” (capitalized) when prompted for
a letter, then the output should show all employees whose last name starts with the letter
“H”​.

SELECT INITCAP(last_name), LENGTH(last_name)


FROM employees
WHERE last_name LIKE '&start_letter%'
ORDER BY last_name;
6. Modify query in question (5) such that the case of the entered letter does not affect the
output. The entered letter must be capitalized before being processed by the SELECT
query.

SELECT INITCAP(last_name) "Name", LENGTH(last_name) "Length"


FROM employees
WHERE last_name LIKE UPPER('&start_letter%' ) ORDER BY last_name;

7. The HR department wants to find the duration of employment for each employee. For
each employee, display the last name and calculate the number of months between today
and the date on which the employee was hired. Label the column as MONTHS_WORKED.
Sort the results by the number of months employed. The number of months must be
rounded to the closest whole number.

SELECT last_name, ROUND(MONTHS_BETWEEN(SYSDATE, hire_date)) MONTHS_WORKED


FROM employees
ORDER BY months_worked;

You might also like