Oracle Database Quiz Questions

Course Name:Oracle
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:GROUP BY
Current Quiz Count:30
Progress
0%
Q1
True / False

In Oracle, the GROUP BY clause is used to group rows that have the same values in specified columns into summary rows.

Q2
True / False

The GROUP BY clause must be used with an aggregate function such as SUM, COUNT, AVG, MIN, or MAX in Oracle.

Q3
True / False

In Oracle, columns in the GROUP BY clause must also appear in the SELECT list unless they are used with an aggregate function.

Q4
True / False

In Oracle, the GROUP BY clause can be used with the ORDER BY clause to sort the grouped result set.

Q5
True / False

In Oracle, you can use column aliases defined in the SELECT clause in the GROUP BY clause.

Q6
True / False

The GROUP BY clause in Oracle can group by expressions, including calculated columns and functions.

Q7
True / False

In Oracle, the GROUP BY clause can be used in combination with the HAVING clause to filter groups based on aggregate values.

Q8
True / False

In Oracle, the GROUP BY clause can be used to group by multiple columns, resulting in a multi-level grouping.

Q9
True / False

The GROUP BY clause in Oracle can be used with the ROLLUP and CUBE extensions to generate subtotals and grand totals.

Q10
True / False

The Oracle Certified Professional (OCP) exam includes knowledge on using the GROUP BY clause effectively, optimizing its performance, and understanding its interaction with aggregate functions and extensions like ROLLUP and CUBE.

Q11
Single Choice

What is the primary purpose of the GROUP BY clause in Oracle SQL?

Q12
Single Choice

Which of the following Oracle SQL queries correctly uses the GROUP BY clause?

SQL Code
SELECT department_id, COUNT(*)
FROM employees
GROUP BY department_id;
Q13
Single Choice

Which clause is mandatory when using aggregate functions with the GROUP BY clause in Oracle SQL?

Q14
Single Choice

What will the following Oracle SQL query output?

SQL Code
SELECT job_id, AVG(salary)
FROM employees
GROUP BY job_id;
Q15
Single Choice

Which Oracle SQL query would you use to find the maximum salary in each department?

SQL Code
SELECT department_id, MAX(salary)
FROM employees
GROUP BY department_id;
Q16
Single Choice

What will the following Oracle SQL query return?

SQL Code
SELECT department_id, COUNT(employee_id)
FROM employees
WHERE salary > 5000
GROUP BY department_id;
Q17
Single Choice

In Oracle SQL, which of the following is correct when using GROUP BY with multiple columns?

SQL Code
SELECT department_id, job_id, SUM(salary)
FROM employees
GROUP BY department_id, job_id;
Q18
Single Choice

Which Oracle SQL query would you use to list departments with more than 10 employees?

SQL Code
SELECT department_id, COUNT(employee_id) AS employee_count
FROM employees
GROUP BY department_id
HAVING COUNT(employee_id) > 10;
Q19
Single Choice

What will the following Oracle SQL query return?

SQL Code
SELECT job_id, SUM(salary) AS total_salary
FROM employees
WHERE department_id IN (10, 20)
GROUP BY job_id
HAVING SUM(salary) > 50000;
Q20
Single Choice

Which of the following Oracle SQL queries demonstrates an advanced use of GROUP BY with a complex expression?

SQL Code
SELECT TO_CHAR(hire_date, 'YYYY') AS hire_year, department_id, COUNT(employee_id) AS hires_per_year
FROM employees
GROUP BY TO_CHAR(hire_date, 'YYYY'), department_id
ORDER BY hire_year DESC;
Q21
Multiple Choice

Which SQL code snippet correctly uses the GROUP BY clause to group employees by their department in Oracle?

SQL Code
SELECT department_id, COUNT(*) AS num_employees
FROM employees
GROUP BY department_id;

SELECT department_id, COUNT(*)
FROM employees
GROUP BY department_id;

SELECT COUNT(*), department_id
FROM employees
GROUP BY department_id;
Q22
Multiple Choice

Which SQL code snippet demonstrates how to use the GROUP BY clause with a HAVING clause in Oracle?

SQL Code
SELECT department_id, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 50000;

SELECT department_id, AVG(salary)
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 50000;

SELECT department_id, COUNT(*)
FROM employees
GROUP BY department_id
HAVING COUNT(*) > 10;
Q23
Multiple Choice

Which SQL code snippet uses the GROUP BY clause to group products by category and calculate the total quantity in stock in Oracle?

SQL Code
SELECT category_id, SUM(quantity_in_stock) AS total_quantity
FROM products
GROUP BY category_id;

SELECT category_id, SUM(quantity_in_stock)
FROM products
GROUP BY category_id;

SELECT category_id, SUM(quantity_in_stock) total_quantity
FROM products
GROUP BY category_id;
Q24
Multiple Choice

Which SQL code snippet demonstrates how to use the GROUP BY clause to find the maximum salary in each department in Oracle?

SQL Code
SELECT department_id, MAX(salary) AS max_salary
FROM employees
GROUP BY department_id;

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

SELECT department_id, MAX(salary) max_salary
FROM employees
GROUP BY department_id;
Q25
Multiple Choice

Which SQL code snippet uses the GROUP BY clause to count the number of employees in each job title in Oracle?

SQL Code
SELECT job_title, COUNT(*) AS num_employees
FROM employees
GROUP BY job_title;

SELECT job_title, COUNT(*)
FROM employees
GROUP BY job_title;

SELECT COUNT(*), job_title
FROM employees
GROUP BY job_title;
Q26
Multiple Choice

Which SQL code snippet demonstrates advanced use of the GROUP BY clause to calculate the average salary and group by department and job title in Oracle?

SQL Code
SELECT department_id, job_title, AVG(salary) AS avg_salary
FROM employees
GROUP BY department_id, job_title;

SELECT department_id, job_title, AVG(salary)
FROM employees
GROUP BY department_id, job_title;

SELECT department_id, job_title, AVG(salary) avg_salary
FROM employees
GROUP BY department_id, job_title;
Q27
Multiple Choice

Which SQL code snippet uses the GROUP BY clause to find the total sales amount for each product in Oracle?

SQL Code
SELECT product_id, SUM(sales_amount) AS total_sales
FROM sales
GROUP BY product_id;

SELECT product_id, SUM(sales_amount)
FROM sales
GROUP BY product_id;

SELECT product_id, SUM(sales_amount) total_sales
FROM sales
GROUP BY product_id;
Q28
Multiple Choice

Which SQL code snippet demonstrates advanced use of the GROUP BY clause with a JOIN to calculate the average order amount by customer in Oracle?

SQL Code
SELECT c.customer_id, AVG(o.order_amount) AS avg_order_amount
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id;

SELECT customer_id, AVG(order_amount) AS avg_order_amount
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id;

SELECT c.customer_id, AVG(order_amount) avg_order_amount
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
GROUP BY c.customer_id;
Q29
Multiple Choice

Which SQL code snippet demonstrates certification-level use of the GROUP BY clause to calculate the total revenue for each region in Oracle?

SQL Code
SELECT r.region_id, SUM(o.order_amount) AS total_revenue
FROM regions r
JOIN orders o ON r.region_id = o.region_id
GROUP BY r.region_id;

SELECT region_id, SUM(order_amount) AS total_revenue
FROM regions r
JOIN orders o ON r.region_id = o.region_id
GROUP BY r.region_id;

SELECT r.region_id, SUM(order_amount) total_revenue
FROM regions r
JOIN orders o ON r.region_id = o.region_id
GROUP BY r.region_id;
Q30
Multiple Choice

Which SQL code snippet uses the GROUP BY clause with multiple columns to group sales by region and product category in Oracle?

SQL Code
SELECT r.region_name, p.category_name, SUM(s.sales_amount) AS total_sales
FROM sales s
JOIN regions r ON s.region_id = r.region_id
JOIN products p ON s.product_id = p.product_id
GROUP BY r.region_name, p.category_name;

SELECT region_name, category_name, SUM(sales_amount)
FROM sales s
JOIN regions r ON s.region_id = r.region_id
JOIN products p ON s.product_id = p.product_id
GROUP BY region_name, category_name;

SELECT r.region_name, p.category_name, SUM(sales_amount) total_sales
FROM sales s
JOIN regions r ON s.region_id = r.region_id
JOIN products p ON s.product_id = p.product_id
GROUP BY r.region_name, p.category_name;