PostgreSQL Database Quiz Questions

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

The HAVING clause in PostgreSQL is used to filter rows after the GROUP BY clause.

Q2
True / False

In PostgreSQL, the HAVING clause can be used without a GROUP BY clause.

Q3
True / False

The HAVING clause in PostgreSQL can include aggregate functions like SUM and COUNT.

Q4
True / False

In PostgreSQL, the HAVING clause is executed before the GROUP BY clause.

Q5
True / False

You can use the HAVING clause in PostgreSQL to filter individual rows in a result set.

Q6
True / False

In PostgreSQL, it is possible to use a subquery within a HAVING clause.

Q7
True / False

PostgreSQL allows the use of window functions directly in the HAVING clause.

Q8
True / False

In PostgreSQL, the HAVING clause can reference columns that are not included in the GROUP BY clause or an aggregate function.

Q9
True / False

The HAVING clause can be used in conjunction with the ORDER BY clause in PostgreSQL.

Q10
True / False

In PostgreSQL, you can use the HAVING clause to filter results based on a calculated column alias defined in the SELECT clause.

Q11
Single Choice

What is the primary purpose of the HAVING clause in PostgreSQL?

Q12
Single Choice

Which of the following SQL statements correctly uses the HAVING clause in PostgreSQL?

SQL Code
SELECT department, COUNT(*)
FROM employees
GROUP BY department
HAVING COUNT(*) > 5;
Q13
Single Choice

Can the HAVING clause be used without a GROUP BY clause in PostgreSQL?

Q14
Single Choice

Given the following SQL query, what does the HAVING clause do?

SQL Code
SELECT manager_id, SUM(salary)
FROM employees
GROUP BY manager_id
HAVING SUM(salary) > 50000;
Q15
Single Choice

In PostgreSQL, which clause is processed first in a query with both GROUP BY and HAVING?

Q16
Single Choice

Consider the following query

SQL Code
SELECT department, AVG(salary)
FROM employees
GROUP BY department
HAVING AVG(salary) > 60000;
What does this query return?
Q17
Single Choice

Which of the following queries correctly identifies departments where the average employee salary is above $75,000 and the total salary exceeds $500,000?

SQL Code
SELECT department, AVG(salary) AS avg_salary, SUM(salary) AS total_salary
FROM employees
GROUP BY department
HAVING AVG(salary) > 75000 AND SUM(salary) > 500000;
Q18
Single Choice

What would be the result of the following query in PostgreSQL?

SQL Code
SELECT job_title, COUNT(*)
FROM employees
GROUP BY job_title
HAVING COUNT(*) > 10 OR COUNT(*) < 3;
Q19
Single Choice

How does the HAVING clause in PostgreSQL differ from the WHERE clause when both are used in a query with GROUP BY?

Q20
Single Choice

In the context of PostgreSQL, consider a table sales with columns product_id, region, and revenue. Which of the following queries correctly retrieves regions where the average revenue per product exceeds $10,000 and the total revenue is more than $1,000,000?

SQL Code
SELECT region, AVG(revenue) AS avg_revenue, SUM(revenue) AS total_revenue
FROM sales
GROUP BY region
HAVING AVG(revenue) > 10000 AND SUM(revenue) > 1000000;
Q21
Multiple Choice

Which SQL scripts correctly use the HAVING clause to filter groups in PostgreSQL?

Q22
Multiple Choice

Identify the SQL scripts that correctly use the HAVING clause with multiple conditions in PostgreSQL.

Q23
Multiple Choice

Determine the SQL scripts that correctly use the HAVING clause with aggregate functions in PostgreSQL.

Q24
Multiple Choice

Select the SQL scripts that correctly use HAVING with COUNT in PostgreSQL.

Q25
Multiple Choice

Identify the SQL scripts that correctly use HAVING with DISTINCT in PostgreSQL.

Q26
Multiple Choice

Determine the SQL scripts that correctly use HAVING with complex expressions in PostgreSQL.

Q27
Multiple Choice

Identify the SQL scripts that correctly combine HAVING and WHERE clauses in PostgreSQL.

Q28
Multiple Choice

Determine the SQL scripts that correctly use HAVING with subqueries in PostgreSQL.

Q29
Multiple Choice

Select the SQL scripts that correctly use HAVING with conditional expressions in PostgreSQL.

Q30
Multiple Choice

Identify the SQL scripts that correctly use HAVING with CASE statements in PostgreSQL.