Uploaded by Jhay-ar Perez

PEREZ finalLab1-ToStuds (1)

advertisement
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:
- Create a list of all tables whose first
two characters in the name of the
table is JO.
- The tables must be owned by the
current Oracle User.
Tables Used:
- User_tables
Screenshot:
Query:
SQL>
SELECT table_name, owner
FROM all_tables
WHERE table_name LIKE'JO%'
2. Problem:
- Create a list that includes the first
initial of every employee's first name,
a space, and the last name of the
employee.
Tables Used:
- Employees
Answer
Query:
SQL>
SELECT SUBSTR(first_name,1,1)
|| ' ' || last_name
FROM hr.employees;
3. Problem:
- Create a list of every employee's first
name concatenated to a space and
the employee's last name, and the
email of all employees where the
email address contains the string 'IN'.
Tables Used:
- Employees
Answer:
Query:
SQL>
SELECT first_name ||' ' || last_name,
email
FROM hr.employees
WHERE email LIKE'%IN%';
4. Create a list of 'smallest' last name
and the 'highest' last name from the
employees table.
6. Create a list of every employee and his
related job title sorted by job_title.
• Tables Used: – Employees, Jobs
Answer:
Query:
SELECT
SUBSTR(employees.first_name,1,1)
|| ' ' ||
employees.last_name "Employee Name",
jobs.job_title "Jobs"
FROM hr.employees, hr.jobs
WHERE employees.job_id = jobs.job_id;
• Tables Used: – Employees
Output:
Answer:
Query:
SELECT
last_name AS "First Last Name",
last_name AS "Last Last Name"
FROM hr.employees
ORDER BY "First Last Name" ASC, "Last
Last Name" DESC;
7. Create a list of every employee's job,
the salary ranges within the job, and
the employee's salary. – List the
lowest and highest salary range within
each job with a dash to separate the
salaries like this: 100 – 200.
• Tables Used: – Employees, Jobs
Output:
5. Create a list of weekly salaries from the
employees table where the weekly
salary is between 700 and 3000. – The
salaries should be formatted to include
a $-sign and have two decimal points
like: $9999.99.
• Tables Used: – Employees
Answer:
Query:
SELECT
TO_CHAR(ROUND(salary/4,2),
'fm$99,999.00')
AS "Weekly Salary"
FROM hr.employees
WHERE salary BETWEEN 700 AND
3000;
Output:
Answer:
Query:
SELECT
SUBSTR(employees.first_name,1,1)
|| ' ' ||
employees.last_name "Employee Name",
jobs.job_title "Jobs",
MIN_SALARY ||'-'|| MAX_SALARY
"Salary Range",
employees.salary "Employee's Salary"
FROM hr.employees, hr.jobs
WHERE employees.job_id = jobs.job_id;
Output:
8. Using an ANSII join method, create a
list of every employee's first initial and
last name, and department name. –
Make sure the tables are joined on all
of the foreign keys declared between
the two tables.
• Tables Used:
Departments
–
Employees,
Answer:
SELECT SUBSsTR(first_name,1,1)
|| ' ' ||
last_name "Employee Name",
department_name
FROM hr.employees NATURAL JOIN
hr.departments;
9. Change the previous listing to join
only on the department_id column.
• Tables Used:
Departments
–
Employees,
SELECT
DECODE
(manager_id,
null,'Nobody','Somebody') "Works For",
last_name "Last Name"
FROM hr.employees;
Output:
11. Create a list of every employee's first
initial and last name, salary, and a yes
or no to show whether or not an
employee makes a commission. – Fix
this query to produce the result.
Answer:
Query:
SELECT SUBSTR(first_name,1,1)||' '||
last_name "Employee Name", salary
"Salary",
DECODE
(commission_pct,null,'No','Yes')
commission
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.
• Tables Used: – Employees
Answer:
Query:
12. Create a list of every employee's last
name, department name, city, and
state_province.
–
Include
departments
without
employees.
–
An outer join is required.
•
Tables Used:
–
Employees, Departments, Locations
SELECT
E.last_name,
E.salary,
J.grade_level
FROM hr.employees E
JOIN hr.job_grades J
ON E.salary BETWEEN J.lowest_sal
AND J.highest_sal;
SELECT
E.last_name,
D.department_name,
L.city,
L.state_province
FROM hr.employees E
JOIN hr.departments D
ON E.department_id=D.department_id
JOIN hr.locations L
ON D.location_id = L.location_id;
15. Produce a list of every employee's last
name and department name.
–
Include both employees without
departments, and departments without
employees.
• Tables Used:
–
Employees, Departments
13. Create a list of every employee's first and
last names, and the first occurrence of:
commission_pct, manager_id, or -1.
–
If an employee gets commission, display
the commission_pct column; if no
commission, then display his manager_id;
if he has neither commission nor
manager, then the number -1.
• Tables Used:
–
Employees
SELECT
first_name
Name",last_name "Last Name",
COALESCE
(commission_pct,
manager_id, commission_pct,
-1)
AS "Which Function???"
FROM hr.employees;
"First
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
SELECT
E.last_name,
D.department_name
FROM hr.employees E
JOIN hr.departments D
ON
E.department_id=D.department_id;
16. Create a treewalking list of every
employee's last name, his manager's
last name, and his position in the
company.
–
The top level manager has position
1, this manager's subordinates
position 2, their subordinates
position 3, and so on.
–
Start the listing with employee
number 100.
• Tables Used:
–
Employees
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
Download
Study collections