0% found this document useful (0 votes)
242 views5 pages

Problem

1. The document is a laboratory activity assessment from a Database Systems 1 course. It contains 16 problems to write SQL queries against an Oracle database to retrieve employee data. 2. The problems include writing queries to list employee names with their emails containing a string, employees and their job titles sorted by job title, weekly salaries between $700-$3,000, and joining tables on foreign keys. 3. Functions used in the queries include SUBSTR, DECODE, ROUND, and outer joins to return data from tables even without matches. The goal is to write SQL statements to retrieve the specified data and return the results and queries.

Uploaded by

Muhammad Qodly
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)
242 views5 pages

Problem

1. The document is a laboratory activity assessment from a Database Systems 1 course. It contains 16 problems to write SQL queries against an Oracle database to retrieve employee data. 2. The problems include writing queries to list employee names with their emails containing a string, employees and their job titles sorted by job title, weekly salaries between $700-$3,000, and joining tables on foreign keys. 3. Functions used in the queries include SUBSTR, DECODE, ROUND, and outer joins to return data from tables even without matches. The goal is to write SQL statements to retrieve the specified data and return the results and queries.

Uploaded by

Muhammad Qodly
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/ 5

Technological Institute of the Philippines

938 Aurora Blvd. Cubao, Quezon City

College of Information Technology Education

ITE 006 – Database Systems 1 (Oracle 1)

Final Period
Ensuring Quality Query Results

Name: Perez Jr., Jose A. Date: February 20, 2019


Program / Section: IT22FA1 Instructor: Ms. Roxanne A. Pagaduan
Assessment Task: Laboratory Activity No 1

The following questions support the attainment of CILO:


1. Write SQL statements based on given problems and retrieve data in the database

Instructions:
- Read the questions carefully.
- Provide the screenshots of your query and output. (include your full name in each screenshot)
- Write your final answer query in your answer sheet. NO Erasure.
- Total Points: 27 (1 point each)

1. Problem: a space, and the last name of the


- Create a list of all tables whose first employee.
two characters in the name of the
table is JO. Tables Used:
- The tables must be owned by the - Employees
current Oracle User.
Tables Used: Answer
- User_tables Query:

Screenshot: SQL>
SELECT SUBSTR(first_name,1,1)
Query: || ' ' || last_name
FROM hr.employees;
SQL>
SELECT table_name, owner
FROM all_tables 3. Problem:
WHERE table_name LIKE'JO%' - Create a list of every employee's first
name concatenated to a space and
the employee's last name, and the
2. Problem: email of all employees where the
- Create a list that includes the first email address contains the string 'IN'.
initial of every employee's first name, Tables Used:
- Employees
Answer: 6. Create a list of every employee and his
Query: related job title sorted by job_title.
SQL>
SELECT first_name ||' ' || last_name, • Tables Used: – Employees, Jobs
email
FROM hr.employees Answer:
WHERE email LIKE'%IN%'; Query:
SELECT
SUBSTR(employees.first_name,1,1)
|| ' ' ||
4. Create a list of 'smallest' last name employees.last_name "Employee Name",
and the 'highest' last name from the jobs.job_title "Jobs"
employees table. FROM hr.employees, hr.jobs
WHERE employees.job_id = jobs.job_id;
• Tables Used: – Employees
Output:
Answer:
Query: 7. Create a list of every employee's job,
SELECT the salary ranges within the job, and
last_name AS "First Last Name", the employee's salary. – List the
last_name AS "Last Last Name" lowest and highest salary range within
FROM hr.employees each job with a dash to separate the
ORDER BY "First Last Name" ASC, "Last salaries like this: 100 – 200.
Last Name" DESC;
• Tables Used: – Employees, Jobs
Output:
Answer:
5. Create a list of weekly salaries from the Query:
employees table where the weekly SELECT
salary is between 700 and 3000. – The SUBSTR(employees.first_name,1,1)
salaries should be formatted to include || ' ' ||
a $-sign and have two decimal points employees.last_name "Employee Name",
like: $9999.99. jobs.job_title "Jobs",
MIN_SALARY ||'-'|| MAX_SALARY
• Tables Used: – Employees "Salary Range",
employees.salary "Employee's Salary"
Answer: FROM hr.employees, hr.jobs
Query: WHERE employees.job_id = jobs.job_id;
SELECT
TO_CHAR(ROUND(salary/4,2), Output:
'fm$99,999.00')
AS "Weekly Salary" 8. Using an ANSII join method, create a
FROM hr.employees list of every employee's first initial and
WHERE salary BETWEEN 700 AND last name, and department name. –
3000; Make sure the tables are joined on all
Output:
of the foreign keys declared between SELECT DECODE (manager_id,
the two tables. null,'Nobody','Somebody') "Works For",
last_name "Last Name"
• Tables Used: – Employees, FROM hr.employees;
Departments Output:

Answer: 11. Create a list of every employee's first


initial and last name, salary, and a yes
SELECT SUBSsTR(first_name,1,1) or no to show whether or not an
|| ' ' || employee makes a commission. – Fix
last_name "Employee Name", this query to produce the result.
department_name
FROM hr.employees NATURAL JOIN Answer:
hr.departments; Query:
SELECT SUBSTR(first_name,1,1)||' '||
last_name "Employee Name", salary
9. Change the previous listing to join "Salary",
only on the department_id column. DECODE
(commission_pct,null,'No','Yes')
• Tables Used: – Employees, commission
Departments FROM hr.employees;

Answer:
Query:

SELECT
SUBSTR(first_name,1,1)
|| ' ' ||
last_name "Employee Name",
department_name "Department Name"
FROM hr.employees e JOIN
hr.departments d
ON(e.department_id = d.department_id);

Output:

10. Create a list of every employee's last


name, and the word nobody or
somebody depending on whether or
not the employee has a manager. –
Use the Oracle DECODE function to
create the list. 12. Create a list of every employee's last
name, department name, city, and
• Tables Used: – Employees state_province.

Answer: Include departments without
Query: employees.
– SELECT E.last_name, E.salary,
An outer join is required. J.grade_level
• FROM hr.employees E
Tables Used: JOIN hr.job_grades J
– ON E.salary BETWEEN J.lowest_sal
Employees, Departments, Locations AND J.highest_sal;

SELECT 15. Produce a list of every employee's last


E.last_name, name and department name.
D.department_name, –
L.city, Include both employees without
L.state_province departments, and departments without
FROM hr.employees E employees.
JOIN hr.departments D • Tables Used:
ON E.department_id=D.department_id –
JOIN hr.locations L Employees, Departments
ON D.location_id = L.location_id;
SELECT
13. Create a list of every employee's first and E.last_name,
last names, and the first occurrence of: D.department_name
commission_pct, manager_id, or -1. FROM hr.employees E
– JOIN hr.departments D
If an employee gets commission, display ON
the commission_pct column; if no E.department_id=D.department_id;
commission, then display his manager_id;
if he has neither commission nor 16. Create a treewalking list of every
manager, then the number -1. employee's last name, his manager's
• Tables Used: last name, and his position in the
– company.
Employees –
The top level manager has position
SELECT first_name "First 1, this manager's subordinates
Name",last_name "Last Name", position 2, their subordinates
COALESCE position 3, and so on.
(commission_pct, –
manager_id, commission_pct, Start the listing with employee
-1) number 100.
AS "Which Function???" • Tables Used:
FROM hr.employees; –
Employees
14. Create a list of every employee's last
name, salary, and job_grade for all
employees working in departments
with a department_id greater than 50.
• Tables Used:

Employees, job_grades
17. Produce a list of the earliest hire
date, the latest hire date, and the
number of employees from the
employees table.

Tables Used:

Employees

18. Create a list of department names


and the departmental costs (salaries
added up).

Include only departments whose
salary costs are between 15000 and
31000, and sort the listing by the
cost.

Tables Used:

Employees, Departments

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy