NEW
Font size
WorksheetsPostgreSQL HAVING Clause Quiz
Total questions: 5
Worksheet time: 3mins
What is the primary purpose of the HAVING clause in PostgreSQL?
To filter rows before grouping
To filter groups after aggregation
To sort the result set
To join tables together
Which of the following statements about HAVING vs WHERE is correct?
HAVING and WHERE can be used interchangeably
WHERE filters rows before grouping, HAVING filters groups after aggregation
HAVING is faster than WHERE in all cases
WHERE can only be used with aggregate functions
In which order do these clauses execute in a PostgreSQL query?
SELECT → WHERE → GROUP BY → HAVING → ORDER BY
WHERE → GROUP BY → HAVING → SELECT → ORDER BY
GROUP BY → WHERE → HAVING → SELECT → ORDER BY
WHERE → SELECT → GROUP BY → HAVING → ORDER BY
Which of the following queries is syntactically correct?
SELECT department FROM employees HAVING COUNT(*) > 5 GROUP BY department
SELECT department FROM employees GROUP BY department HAVING COUNT(*) > 5
SELECT department FROM employees WHERE COUNT(*) > 5 GROUP BY department
SELECT COUNT(*) FROM employees HAVING department = 'Sales'
What will this query return? sqlSELECT category, AVG(price) FROM products GROUP BY category HAVING AVG(price) > 100 AND COUNT(*) >= 3;
All products with price > 100
Categories with at least 3 products and average price > 100
Products in categories where the average price > 100
The first 3 categories with average price > 100
