Homework Week2 2
Homework Week2 2
Week 2
Assignment 1
You have been hired as a SQL programmer for Acme Corporation. Your assignment is
to create some reports based on data from the Human Resources tables.
2. The HR department wants a query to display the last name, job ID, hire date, and
employee ID for each employee, with the employee ID appearing first. Provide an
alias STARTDATE for the HIRE_DATE column. Save your SQL statement to a file
named hw2_task1_02.sql so that you can dispatch this file to the HR
department. Test your query in the file to ensure that it runs correctly.
3. The HR department wants a query to display all unique job IDs from the
EMPLOYEES table.
4. The HR department wants more descriptive column headings for its report on
employees. Copy the statement from hw2_task1_02.sql to a new SQL
Worksheet. Name the columns Emp #, Employee, Job, and Hire Date,
respectively. Then run the query again.
6. To familiarize yourself with the data in the EMPLOYEES table, create a query to
display all the data from that table. Separate each column output by a comma.
Name the column THE_OUTPUT.
2. Create a report that displays the last name and department number for employee
number 176.
4. 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.
7. The HR department needs a report that displays the last name and hire date of
all employees who were hired in 2010.
8. Create a report to display the last name and job title of all employees who do not
have a manager.
9. Create a report to display the last name, salary, and commission of all
employees who earn commissions. Sort the data in descending order of salary
10. Members of the HR department want to have more flexibility with the queries that
you are writing. They would like a report that displays the last name and salary of
employees who earn more than an amount that the user specifies after a prompt.
If you enter 12000 when prompted, the report displays the following results:
11. The HR department wants to run reports based on a manager. Create a query
that prompts the user for a manager ID, and generates the employee ID, last
name, salary, and department for that manager’s employees. The HR
department wants the ability to sort the report on a selected column. You can test
the data with the following values:
a. manager_id = 103, sorted by last_name
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 jobs are either
that of a sales representative or a stock clerk, and whose salaries are not equal
to $2,500, $3,500, or $7,000.
See 2-3: Restricting Data and 2-4: Sorting Data for reference.
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. Save your SQL statement in a file
named hw2_task3_02.sql and run the query.
3. Modify your query in hw2_task3_02.sql to add a column that subtracts the old
salary from the new salary. Label the column Increase.
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 last name starts with the letter entered by the user when prompted. Write
a query such that the case of the letter that is entered does not affect the output.
Give each column an appropriate label.
6. 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
SALARY.
8. Create a query to display the last name and the number of weeks employed for
all employees in department 90. Label this column as TENURE. Truncate the
number of weeks value to 0 decimal places. Show the records in descending
order of the employee’s tenure.
Note: The TENURE value will differ because it depends on the date on which you
run the query.
See 2-5: Computing with Single Row Functions and 2-6: Working with Date
Functions for reference.
Assignment 4
1. Create a report that produces the following for each employee:
<employee last name> earns <salary> monthly but wants <3 times
salary.>. Label the column Dream Salaries.
3. Create a query that displays employees’ last names and commission amounts. If
an employee does not earn commission, show “No Commission.” Label the
column COMM.
4. Using the CASE function, write a query that displays the grade of all employees
based on the value of the JOB_ID column, using the following data:
Job Grade
AD_PRES A
ST_MAN B
IT_PROG C
SA_REP D
ST_CLERK E
None of the above 0
5. Rewrite the statement in the preceding exercise by using the searched CASE
syntax.
6. Rewrite the statement in the preceding exercise by using the DECODE syntax.