You are on page 1of 13

LAB 2

Task 1
Explore the data and tables structure of the HR schema above using SQL Select statement
and the describe command. Construct SQL statements to answer the following queries. Save
your queries in a file (week1.sql) in a folder on your home drive.
1. Select all data from the LOCATIONS table to display its internal structure i.e. attributes
names and datatypes.

2. Show the internal structure of the EMPLOYEES table. Create a report to display
employee number, employee full name (first and last names), job ids and the
department number for each employee. Rename the columns headings to: Emp #, Full
Name, Job Title and Department ID respectively.
3. Write a query to display a unique list job titles from the EMPLOYEES table.

4. Create a report to display employees full name “concatenated”, with their emails and
phone numbers according to the format below.
LAB 3
1. Create a report to display a list of all hotels with details of hotel name and location.
2. Create a report lists full details of all guests.

3. Create a report to display the room number and price of all “Standard” rooms.

4. Create a report to display name and address details for all guests who live in London.

5. Create a report to list all bookings for which no dateTo has been specified.
LAB 4
1. Generate a report to display staff full names (i.e. combination of both first and last
names), commission, and job titles of employees who earn a commission of more than
0.25 percent.

2. Generate a report to display full names (i.e. combination of both first and last names),
job titles and salary for all employees whose salary falls in the range of $5,000 to
$10,000.
3. Modify the previous report display full names (i.e. combination of both first and last
names), job titles and salary for all employees whose salary is NOT in the range of
$5,000 to $10,000.

4. Compare the outputs of queries (2) and (3) above. What is the difference? Explain
why?
5. Create a report to display the full name, job Title, and staring work date for the
following staff members:
a) Mr King, Steven
b) Miss Lorentz, Diana

6. Create a report to display street address, postal code and city name for all offices that
are located in Canada and the United States of America.

7. Run the query (select sysdate from dual) and examine Oracle online documentation.
Explain the purpose of keywords sysdate and dual.
LAB 5
1. Create a report to show staff full names in addition to contact details (email, phone
numbers) for all employees who were hired in January 1996. Display the names in
alphabetical order by last name. Format the report according to the example below.

2. Modify the report you created in question 8 to display all the employees (Employee
Full Name) who were hired after December 1999, display the results in descending
order by hire date.
3. List all staff members’ whose first name starts with the letter (s) and ends with the
letter (n)?

4. List the employees who hold the following job titles (AC_MGR, AD_VP, FI_MGR,
HR_REP, PR_REP)?
5. The HR department wants to run reports in order to generate details of employees
working in a specific department. Create a dynamic report that prompts the user for a
department ID, and then displays the employee ID, last name, salary, and department
for that manager’s employees. Run the report for four different department numbers.
How many rows did you get for each department?

6. List full details for all rooms whose price is above $40. Your results must be sorted in
ascending order by room type and price.
7. List the names and full addresses of all guests who live in AUT accommodation at “8
Mount St”

LAB 6
1. Suppose that you have two tables, EMPLOYEE and EMPLOYEE_1. The EMPLOYEE table
contains the records (employee names) for three employees: Alice Cordoza , John
Cretchakov, and Anne McDonald. The EMPLOYEE_1 table contains the records
(employee names) for employees John Cretchakov and Mary Chen. Given this
information, what is the query output for the UNION query? (List the query output.)
Note: UNION yields unique rows. In other words, UNION eliminates duplicates rows. On the other
hand, a UNION ALL operator will yield all rows of both relations, including duplicates. Notice that for
two rows to be duplicated, they must have the same values in all columns.
The query output will be:
2. Given the employee information in Question (i) above, what is the query output for
the UNION ALL query? (List the query output.) The query output will be:
3. Given the employee information in Question (i) above, what is the query output for
the INTERSECT query? (List the query output.)
The query output will be:
5. Given the employee information in Question (i) above, what is the query output for
the MINUS query? (List the query output.)
Use the HOTEL database to create the following queries.
1. Generate a report to list room details (price and type) of all rooms at the Grosvenor
Hotel (Hint: use JOINS)
a). Generate the report in (1) using a subquery.

2. Generate a report to display the details of all guests who have made booking. Your
output should display the following information: Guestname, Hotel name, booking
from date and booking end date. Format the report as below:

LAB 7
Use the HR database to create the following SQL queries.
1- Generate a report to display staff full names, jobs and department names. Rename the
column headings to “Full Name”, “Job Title”, and “Department Name”. Order the report
alphabetically by last name
2- Generate a report to display the full names (i.e. combination of first and last names),
email address (generated by concatenating email id with @MEGACORP.COM),
department name and office address (city and country) of all employees. Sort the output
by last name. Rename the columns and format the report as below:
3- Modify the previous question to generate a dynamic report that display the employee
details (as listed in (2) above) for a specific country (i.e. the user should be prompted to
enter a country name). Run the report by entering different countries (for example,
Germany and Italy). Explain the report output and identify potential format
improvements.
4- Generate a report to display the full names and department names of all employees. The
report must also include all departments including those that do not have any employees
assigned to them.
5- Generate a report to display the employee name and employee number along with their
manager’s name and manager number. Label the columns Employee, Emp#, Manager,
and Mgr#, respectively. Format the report as below:

6- Explain why the previous report generated the details of 106 only employees? (note that
there are a total of 107 employees in the employees table)
7- Modify query (6) so that the output displays all 107 employees.
8- Generate a report to display staff full name, job title and salary of all staff members who
earn more than the salary earned by employee “Oliver Tuvault”.

You might also like