wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PostgreSQL HAVING Clause Quiz

Total questions: 5

Worksheet time: 3mins

Name
Class
Date
1.

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

a)

To filter rows before grouping

b)

To filter groups after aggregation

c)

To sort the result set

d)

To join tables together

2.

Which of the following statements about HAVING vs WHERE is correct?

a)

HAVING and WHERE can be used interchangeably

b)

WHERE filters rows before grouping, HAVING filters groups after aggregation

c)

HAVING is faster than WHERE in all cases

d)

WHERE can only be used with aggregate functions

3.

In which order do these clauses execute in a PostgreSQL query?

a)

SELECT → WHERE → GROUP BY → HAVING → ORDER BY

b)

WHERE → GROUP BY → HAVING → SELECT → ORDER BY

c)

GROUP BY → WHERE → HAVING → SELECT → ORDER BY

d)

WHERE → SELECT → GROUP BY → HAVING → ORDER BY

4.

Which of the following queries is syntactically correct?

a)

SELECT department FROM employees HAVING COUNT(*) > 5 GROUP BY department

b)

SELECT department FROM employees GROUP BY department HAVING COUNT(*) > 5

c)

SELECT department FROM employees WHERE COUNT(*) > 5 GROUP BY department

d)

SELECT COUNT(*) FROM employees HAVING department = 'Sales'

5.

What will this query return? sqlSELECT category, AVG(price) FROM products GROUP BY category HAVING AVG(price) > 100 AND COUNT(*) >= 3;

a)

All products with price > 100

b)

Categories with at least 3 products and average price > 100

c)

Products in categories where the average price > 100

d)

The first 3 categories with average price > 100