You are on page 1of 4

BSAN 310 SQL #2 Initial Exercise

Use your Live SQL account ( https://livesql.oracle.com/apex/f?p=590:1000)

DUE: Nov 3rd (11:59pm CST)


After Logging In, click on “Start Coding Now” or Click on “SQL Worksheet” on
top left-side menu...you’ll see a screen similar to the one below:

Initially we will work just with the HR.EMPLOYEES table.

For this assignment, write the SQL statement in Live SQL and then
run/execute it. Once you see the result copy your SQL statement and paste
it into this Word document (be sure to save this Word document). I don’t
need to see your output.

NOTE: To learn SQL you need to actually run the SQL statements in Live SQL.
Every semester students copy other students’ statements or type SQL
statements and don’t run them (they will have errors keeping them from running).
This behavior will undermine you learning SQL and reduces what you are
learning in this course. For your own benefit, don’t do this.

Once you complete all the problems, submit this Word document as your SQL
Assignment #2.

TIPS:
Ensure all your column names in your SELECT clause are spelled correctly
Make sure you put commas after each column/attribute name in the SELECT
clause (but not if using aliases) and don’t put a comma after the last column
name in the SELECT clause.
Put a semicolon ; at the end of your SQL statement

1. Retrieve the first names and last names and employee IDs from our company
and display the results exactly as: First, Last, Department ID, and Employee
Identification Number (NOTE: they are not in all caps) (use the SQL Alias
function/Keyword to do this)…make sure your display is exactly like: First Last
Department ID Employee Identification Number with the column/attributes
names.
SELECT first_name AS First,
last_name AS Last,
department_id AS "Department ID",
employee_id AS "Employee Identification Number"
FROM HR.EMPLOYEES;

2. The HR department wants a report/query to display all unique (that is no


duplicates) department IDs from the HR.EMPLOYEES table.
SELECT DISTINCT JOB_ID FROM HR.EMPLOYEES;
3. The HR (Human Resources) department wants more descriptive column
headings for its report on employees. They want employee ids, last names and
the hired dates displayed in a report, but with specific column/attribute headers.
Create an SQL statement to rename the column headings in the output/display
as: “Employee Number” (for employee_ID), “Last Name of Employee” (for
last_name), and “Date Hired” (for hire_date), respectively. Your display/output
column/attribute names/headers should appear exactly as shown within the
quotation marks above.
SELECT employee_id AS "Employee Number",
last_name AS "Last Name of Employee",
hire_date AS "Date Hired" FROM HR.EMPLOYEES;

4. Run an SQL query that displays first names, last names, salaries, employee
ID numbers and job ids for all employees in the HR.EMPLOYEES table who
have a job id of IT_PROG (IT programmer).
SELECT first_name, last_name, salary, employee_id, job_id FROM
HR.EMPLOYEES
WHERE job_id = 'IT_PROG';

5. Create a report that displays only the last name and department number for
the employee with an employee id of 120.
SELECT last_name, department_id FROM HR.EMPLOYEES
WHERE employee_id = 120;

6. Display the last names, salaries, and job ids of all employees that have a job
id containing the word MAN in it (meaning they are some sort of manager.
SELECT last_name, salary, job_id FROM HR.EMPLOYEES
WHERE job_id LIKE '%MAN';

7. The HR department needs a report that displays the first name, last name and
salary of employees who earn at least $7,000 or more (NOTE: Look at lecture
slide below, which operator(s) would you use; HINT: you don’t use just the =
operator you have to use the = and another operator together)
SELECT first_name, last_name, salary FROM HR.EMPLOYEES
WHERE salary >= 7000;

You might also like