Q1
True / FalseThe HAVING clause in Oracle is used to filter groups of rows created by the GROUP BY clause.
The HAVING clause filters groups based on specified conditions, similar to how the WHERE clause filters individual rows.
Q2
True / FalseThe HAVING clause can be used without a GROUP BY clause in Oracle.
The HAVING clause is typically used with the GROUP BY clause to filter groups, but in rare cases, it can be used without GROUP BY to apply conditions on aggregate functions.
Q3
True / FalseIn Oracle, the HAVING clause must follow the GROUP BY clause in a query.
The HAVING clause follows the GROUP BY clause and applies conditions to the grouped rows.
Q4
True / FalseIn Oracle, the HAVING clause can include aggregate functions like SUM, COUNT, AVG, MIN, and MAX.
The HAVING clause can include aggregate functions to filter groups based on aggregated values.
Q5
True / FalseThe HAVING clause in Oracle can be combined with the WHERE clause in the same query.
The WHERE clause filters rows before grouping, while the HAVING clause filters groups after the GROUP BY clause has been applied.
Q6
True / FalseIn Oracle, you can use column aliases defined in the SELECT clause within the HAVING clause.
Column aliases defined in the SELECT clause cannot be used directly in the HAVING clause. The original column names or expressions must be used.
Q7
True / FalseThe HAVING clause in Oracle can be used with logical operators like AND and OR to form complex conditions.
The HAVING clause can use logical operators to combine multiple conditions for filtering groups.
Q8
True / FalseIn Oracle, the HAVING clause can be used in subqueries to filter groups in the subquery results.
The HAVING clause can be used in subqueries to apply conditions on grouped results within the subquery.
Q9
True / FalseUsing the HAVING clause instead of the WHERE clause in Oracle can improve query performance.
The HAVING clause is used to filter groups after aggregation, while the WHERE clause filters rows before aggregation. Using WHERE when possible can improve performance by reducing the number of rows to be processed.
Q10
True / FalseThe Oracle Certified Professional (OCP) exam includes knowledge on using the HAVING clause effectively, optimizing its performance, and understanding its interaction with the GROUP BY clause and aggregate functions.
The OCP certification covers advanced topics, including the effective use of the HAVING clause, optimizing its performance, and understanding its interaction with the GROUP BY clause and aggregate functions.
Q21
Multiple ChoiceWhich SQL code snippet correctly uses the HAVING clause to filter departments with an average salary greater than $50,000 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, AVG(salary) avg_salary
FROM employees
GROUP BY department_id
HAVING AVG(salary) > 50000;
Options A, B, and C correctly use the HAVING clause to filter departments with an average salary greater than $50,000. Option D is incorrect as it does not use the HAVING clause.
Q22
Multiple ChoiceWhich SQL code snippet demonstrates how to use the HAVING clause to filter product categories with total sales greater than $100,000 in Oracle?
SQL Code
SELECT category_id, SUM(sales_amount) AS total_sales
FROM sales
GROUP BY category_id
HAVING SUM(sales_amount) > 100000;
SELECT category_id, SUM(sales_amount)
FROM sales
GROUP BY category_id
HAVING SUM(sales_amount) > 100000;
SELECT category_id, SUM(sales_amount) total_sales
FROM sales
GROUP BY category_id
HAVING SUM(sales_amount) > 100000;
Options A, B, and C correctly use the HAVING clause to filter product categories with total sales greater than $100,000. Option D is incorrect as it does not group by category_id.
Q23
Multiple ChoiceWhich SQL code snippet uses the HAVING clause to filter employees by job title where the average salary is less than $40,000 in Oracle?
SQL Code
SELECT job_title, AVG(salary) AS avg_salary
FROM employees
GROUP BY job_title
HAVING AVG(salary) < 40000;
SELECT job_title, AVG(salary)
FROM employees
GROUP BY job_title
HAVING AVG(salary) < 40000;
SELECT job_title, AVG(salary) avg_salary
FROM employees
GROUP BY job_title
HAVING AVG(salary) < 40000;
Options A, B, and C correctly use the HAVING clause to filter employees by job title where the average salary is less than $40,000. Option D is incorrect because it does not filter by job title.
Q25
Multiple ChoiceWhich SQL code snippet uses the HAVING clause to filter regions where the total sales amount is between $200,000 and $500,000 in Oracle?
SQL Code
SELECT region_id, SUM(sales_amount) AS total_sales
FROM sales
GROUP BY region_id
HAVING SUM(sales_amount) BETWEEN 200000 AND 500000;
SELECT region_id, SUM(sales_amount)
FROM sales
GROUP BY region_id
HAVING SUM(sales_amount) BETWEEN 200000 AND 500000;
SELECT region_id, SUM(sales_amount) total_sales
FROM sales
GROUP BY region_id
HAVING SUM(sales_amount) BETWEEN 200000 AND 500000;
Options A, B, and C correctly use the HAVING clause to filter regions where the total sales amount is between $200,000 and $500,000. Option D is incorrect because it does not group by region_id.
Q29
Multiple ChoiceWhich SQL code snippet uses the HAVING clause to filter sales by region where the total revenue exceeds $1,000,000 in Oracle?
SQL Code
SELECT region_id, SUM(revenue) AS total_revenue
FROM sales
GROUP BY region_id
HAVING SUM(revenue) > 1000000;
SELECT region_id, SUM(revenue)
FROM sales
GROUP BY region_id
HAVING SUM(revenue) > 1000000;
SELECT region_id, SUM(revenue) total_revenue
FROM sales
GROUP BY region_id
HAVING SUM(revenue) > 1000000;
Options A, B, and C correctly use the HAVING clause to filter sales by region where the total revenue exceeds $1,000,000. Option D is incorrect because it does not group by region_id.