3 Using Single-Row Functions To Customize Output
3 Using Single-Row Functions To Customize Output
EXERCISE
3
USING SINGLE – ROW FUNCTIONS TO
CUSTOMIZE OUTPUT
NAME SECTION
GJPRosales
Page |2
I. OBJECTIVES
DATEDIFF
PART 1:
Scenario
The HR department needs your assistance in creating some queries.
Task
Write the appropriate SQL statement for the following queries. The result of the
queries will be checked from your computer.
1. 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.
GJPRosales
Page |3
2. Modify your query in Task 1 to add a column that subtracts the old salary from
the new salary. Label the column Increase.
3. Write a query that displays the last name (with the first letter in uppercase and all
other letters in lowercase) and the length of the last name for all employees
whose name starts with the letters “J,” “A,” or “M.” Give each column an
appropriate label. Sort the results by the employees’ last names.
4. 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 employees was hired. Label the
column s MONTHS_WORKED. Order your results by the number of months
employed. Round the number of months up to the closest whole number.
5. Create a query to display the last name and salary for all employees. Format the
salary to be 15 characters long, left-padded with the $ symbol. Label the column
as SALARY.
GJPRosales
Page |4
6. 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 as EMPLOYEES_AND_THEIR_SALARIES.
7. Create a query to display the last name and the number of weeks employed for
all employees in department 90. Label the number of weeks column as TENURE.
Truncate the number of weeks value to 0 decimal places. Show the records in
descending order of the employees’ tenure.
1. What is the difference between scalar function and vector function in database? What
function did we use to display a single row function?
GJPRosales
Page |5
V. REFERENCES
Hoffer, J.A., Prescott, M.B., McFadden, F.R. (2016). Modern Database Management
12th Edition, Prentice Hall.
Microsoft. (2012). Database Administration Fundamentals . USA: Wiley.
GJPRosales