Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Technological Institute of the Philippines

938 Aurora Blvd. Cubao, Quezon City

College of Computer Studies

ITE 014 – Information Management

Midterm Period

Name: REYES, RAXEIN ASHLEY C Date: 02/28/2024


Program / Section: IT22S4 Instructor: Ms. Roxanne A. Pagaduan
Assessment Task: Laboratory Activity No 4: Group Functions

Instructions:
- Connect to the SQL Plus or SQL Developer using a database account. Example: ORA2_PDBRAP
- Analyze and perform the problems below and answer it to the best of your ability
- Include screenshots of your complete SQL Statements and the result/s.
- Include a brief description/caption of each image
- There must be your full name for each image (see example below)
- Save your work as SURNAME1_Lab4.DOCX (Ex. Pagaduan_Lab4.DOCX).
- Each item corresponds to one (1) point, total points are 12.

Sample: Questions:

Question: Part 1:TRUE or FALSE: Determine the validity


Display all the departments' information. of the following three statements.

Answer: 1. Group functions work across many rows


Query: to produce one result per group.
SQL> SELECT * Answer:
FROM departments; TRUE

Output: 2. Group functions include nulls in


calculations.
Answer:
FALSE

3. The WHERE clause restricts rows before


inclusion in a group calculation
Answer:
TRUE
Part 2: The HR department needs the SELECT ROUND(MAX(salary),0)
following reports: "Maximum",

4. Find the highest, lowest, sum, and ROUND(MIN(salary),0) "Minimum",


average salary of all employees. Label
the columns ROUND(SUM(salary),0) "Sum",
Maximum, Minimum, Sum, and Average,
respectively. Round your results to the ROUND(AVG(salary),0) "Average"
nearest whole number. Place your SQL
FROM employees
statement in a text file named
lab_04_04.sql. GROUP BY job_id;
Answer: Output:
Query:

SELECT ROUND(MAX(salary),0)
"Maximum",

ROUND(MIN(salary),0) "Minimum",

ROUND(SUM(salary),0) "Sum",

ROUND(AVG(salary),0) "Average"

FROM employees;
6. Write a query to display the number of
people with the same job.
Output:
Answer:
Query:

SELECT job_id, COUNT(*)

FROM employees

GROUP BY job_id;

5. Modify the query in lab_04_04.sql to


display the minimum, maximum, sum, Output:
and average salary for each job type.
Resave lab_04_04.sql as lab_04_05.sql.
Run the statement in lab_04_05.sql.

Answer:
Query:
SELECT MAX(salary) - MIN(salary) AS
DIFFERENCE
FROM employees;

Output:

7. Determine the number of managers


without listing them. Label the column
Number of Managers. Hint: Use the
MANAGER_ID column to determine the
number of managers. 9. Create a report to display the manager
number and the salary of the lowest-paid
Answer: employee for that manager. Exclude
Query: anyone whose manager is not known.
Exclude any groups where the minimum
SELECT COUNT(DISTINCT salary is $6,000 or less. Sort the output
manager_id) “Number of Managers” in descending order of salary.
FROM employees;
Answer:
Query:
Output: SELECT manager_id, MIN (salary)

FROM employees
WHERE manager_id IS NOT NULL
GROUP BY manager_id
HAVING MIN(salary) > 6000
ORDER BY MIN(salary) DESC;

Output:

8. Find the difference between the highest


and lowest salaries. Label the column
DIFFERENCE.

Answer:
Query:
10. Using the Oracle database, select the
lowest salary, the most recent hire date,
the last name of the person who is at the
top of an alphabetical list of employees,
and the last name of the person who is at
the bottom of an alphabetical list of
employees. Select only employees who
are in departments 50 or 60.

Answer:
Query:
SELECT MIN(salary) “Lowest Salary”, 12. Write a query that will return both the
MAX(hire_date) “Most Recent Hire maximum and minimum average salary
Date”, MIN(last_name) “Top Last Name”, grouped by department from the
MAX(last_name) “Bottom Last Name” employees table.

FROM employees; Answer:


WHERE department_id IN (50,60); Query:
SELECT (MAX(AVG(salary)),2) AS
Output: “Maximum Average Salary” ,
(MIN(AVG(salary)), 2) AS “Minimum
Average Salary”

FROM employees
GROUP BY department_id;

Output:
11. Write a query that will return the average
of the maximum salaries in each
department for the employees table.

Answer:
Query:

SELECT AVG(MAX(salary))
FROM employees
GROUP BY department_id;

Output:

Honor Pledge: "I affirm that we have not given


or received any unauthorized help on this
assessment and that this work is my own"

You might also like