Q1
True / FalseThe HAVING clause is used to filter records after the GROUP BY clause.
True. The HAVING clause is used to filter groups of records created by the GROUP BY clause, whereas the WHERE clause filters individual records before grouping.
Q2
True / FalseThe HAVING clause can be used without a GROUP BY clause.
False. The HAVING clause is intended to filter results of a GROUP BY clause and cannot be used effectively without it.
Q3
True / FalseThe HAVING clause can only use aggregate functions.
True. The HAVING clause is used to filter records based on aggregate functions such as COUNT(), SUM(), AVG(), etc.
Q4
True / FalseThe WHERE clause can be used to filter records after the GROUP BY clause has been applied.
False. The WHERE clause filters records before grouping. The HAVING clause is used to filter after grouping.
Q5
True / FalseYou can use the HAVING clause to filter groups that have a specific number of records.
True. The HAVING clause can be used to filter groups based on the number of records using aggregate functions like COUNT().
Q6
True / FalseThe HAVING clause can be used to filter rows based on specific column values.
False. The HAVING clause filters based on aggregate values, not individual column values. Individual values should be filtered using the WHERE clause.
Q7
True / FalseThe HAVING clause can be used to filter data from multiple tables in a JOIN operation.
True. The HAVING clause can filter data after performing a JOIN operation if a GROUP BY clause is used.
Q8
True / FalseThe HAVING clause can only be used with SELECT statements.
True. The HAVING clause is only applicable in SELECT statements where a GROUP BY clause is used.
Q9
True / FalseYou can use the HAVING clause to filter out records where the aggregate function result is greater than a certain value.
True. The HAVING clause can filter groups based on the result of aggregate functions, such as keeping groups where the result is greater than a specified value.
Q10
True / FalseThe HAVING clause can be used to filter records before the aggregation process.
False. The HAVING clause is used after the aggregation process, whereas the WHERE clause is used before.
Q11
True / FalseThe HAVING clause is more efficient than the WHERE clause when dealing with aggregated data.
False. The HAVING clause is used for filtering after aggregation, while the WHERE clause is used for filtering before aggregation. Efficiency depends on the specific query and data.
Q12
True / FalseThe HAVING clause can be used to filter groups based on non-aggregate expressions.
False. The HAVING clause is specifically designed for filtering based on aggregate functions, not on non-aggregate expressions.
Q13
True / FalseThe HAVING clause can be used in conjunction with the DISTINCT keyword.
True. The HAVING clause can be used with DISTINCT to filter distinct groups based on aggregate results.
Q14
True / FalseThe HAVING clause cannot be used with subqueries.
False. The HAVING clause can be used with subqueries, typically within the main SELECT statement to filter grouped results from a subquery.
Q15
True / FalseThe HAVING clause is always used after the GROUP BY clause in a SQL query.
True. The HAVING clause is used after the GROUP BY clause to filter the results of the grouping operation.
Q31
Multiple ChoiceWhich SQL queries filter groups based on aggregate values? (Select all that apply)
SQL Code
SELECT DepartmentID, AVG(Salary)
FROM Employees
GROUP BY DepartmentID
HAVING AVG(Salary) > 50000;
SELECT CustomerID, COUNT(OrderID)
FROM Orders
GROUP BY CustomerID
HAVING COUNT(OrderID) > 10;
SELECT ProductID, MIN(Price)
FROM Products
GROUP BY ProductID
HAVING MIN(Price) < 50;
SELECT SalesRepID, SUM(SaleAmount)
FROM Sales
GROUP BY SalesRepID
HAVING SUM(SaleAmount) < 100000;
These queries use the HAVING clause to filter groups based on aggregate values such as AVG(Salary), COUNT(OrderID), MIN(Price), and SUM(SaleAmount).