Which clause is used to restrict the groups to be displayed?

Which clause is used to restrict the groups to be displayed?


This SQL tutorial explains how to use the SQL HAVING clause with syntax and examples.

Description

The SQL HAVING clause is used in combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE.

Syntax

The syntax for the HAVING clause in SQL is:

SELECT expression1, expression2, ... expression_n, 
       aggregate_function (aggregate_expression)
FROM tables
[WHERE conditions]
GROUP BY expression1, expression2, ... expression_n
HAVING condition;

Parameters or Arguments

expression1, expression2, ... expression_nExpressions that are not encapsulated within an aggregate function and must be included in the GROUP BY Clause near the end of the SQL statement.aggregate_functionThis is an aggregate function such as the SUM, COUNT, MIN, MAX, or AVG functions.aggregate_expressionThis is the column or expression that the aggregate_function will be used on.tablesThe tables that you wish to retrieve records from. There must be at least one table listed in the FROM clause.WHERE conditionsOptional. These are the conditions for the records to be selected.HAVING conditionThis is a further condition applied only to the aggregated results to restrict the groups of returned rows. Only those groups whose condition evaluates to TRUE will be included in the result set.

Example - Using SUM function

Let's look at a SQL HAVING clause example that uses the SQL SUM function.

You could also use the SQL SUM function to return the name of the department and the total sales (in the associated department). The SQL HAVING clause will filter the results so that only departments with sales greater than $1000 will be returned.

SELECT department, SUM(sales) AS "Total sales"
FROM order_details
GROUP BY department
HAVING SUM(sales) > 1000;

Example - Using COUNT function

Let's look at how we could use the HAVING clause with the SQL COUNT function.

You could use the SQL COUNT function to return the name of the department and the number of employees (in the associated department) that make over $25,000 / year. The SQL HAVING clause will filter the results so that only departments with more than 10 employees will be returned.

SELECT department, COUNT(*) AS "Number of employees"
FROM employees
WHERE salary > 25000
GROUP BY department
HAVING COUNT(*) > 10;

Example - Using MIN function

Let's next look at how we could use the HAVING clause with the SQL MIN function.

You could also use the SQL MIN function to return the name of each department and the minimum salary in the department. The SQL HAVING clause will return only those departments where the minimum salary is greater than $35,000.

SELECT department, MIN(salary) AS "Lowest salary"
FROM employees
GROUP BY department
HAVING MIN(salary) > 35000;

Example - Using MAX function

Finally, let's look at how we could use the HAVING clause with the SQL MAX function.

For example, you could also use the SQL MAX function to return the name of each department and the maximum salary in the department. The SQL HAVING clause will return only those departments whose maximum salary is less than $50,000.

SELECT department, MAX(salary) AS "Highest salary"
FROM employees
GROUP BY department
HAVING MAX(salary) < 50000;

The ____ clause is used to restrict the groups that will be included in a query result.Select one:a.The correct answer is:HAVINGLIKEb.HAVINGCorrectc.WHEREd.HAVECheck

CorrectMarks for this submission: 1.00/1.00.

6/26/2016New SQL Chapter 4 ReviewQuestionThe ____ clause lets you group data on a particular column.7CorrectMark 1.00 out of1.00GROUPb.GROUP BYCorrectc.SET GROUPd.GROUPINGCheck

Get answer to your question and much more

4/13CorrectMarks for this submission: 1.00/1.00.

QuestionThe ____ function calculates a total of the values in a column.8CorrectMark 1.00 out of1.00CorrectMarks for this submission: 1.00/1.00.TOTALb.CALCULATEc.SUMCorrectd.ADDCheck

Get answer to your question and much more

6/26/2016New SQL Chapter 4 ReviewQuestionThe ____ function determines the number of rows in a table.9CorrectMark 1.00 out of1.00ROW

Get answer to your question and much more

5/13CorrectMarks for this submission: 1.00/1.00.

Question10The ____ operator finds rows that do not contain a null value in the specified column.CorrectMark 1.00 out of1.00b.CALCULATEc.COUNTCorrectd.NUMBERCheckThe correct answer is:COUNTCorrectMarks for this submission: 1.00/1.00.Select one:a.The correct answer is:IS NOT NULLIS NULLb.NOT NULLc.!NULLd.IS NOT NULLCorrectCheck

6/26/2016New SQL Chapter 4 ReviewQuestion11The ____ operator is inclusive, meaning that a value equal to either end would be selectCorrectMark 1.00 out of1.00ANDb.BETWEENCorrectc.ORd.NOTCheck

Get answer to your question and much more

6/13b.BETWEENCorrectc.DISTINCTd.GROUPCheckThe correct answer is:BETWEENCorrectMarks for this submission: 1.00/1.00.

Question12The ____ operator specifies a range of values in a condition.CorrectMark 1.00 out of1.00CorrectMarks for this submission: 1.00/1.00.LIKE

Get answer to your question and much more

6/26/2016New SQL Chapter 4 Review7/13

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

Which clause restricts groups displayed in the query results?

A HAVING clause restricts the results of a GROUP BY in a SelectExpression. The HAVING clause is applied to each group of the grouped table, much as a WHERE clause is applied to a select list. If there is no GROUP BY clause, the HAVING clause is applied to the entire result as a single group.

Which clause is used to restrict groups?

A WHERE clause can be used to restrict both rows and groups.

Which clause is used to restrict the groups that will be included in a query result group of answer choices like HAVING WHERE have?

The HAVING clause is used to restrict groups, based on aggregated results.

Which clause is used to restrict the records to be displayed?

In the SELECT argument, the LIMIT clause is used to LIMIT the number of rows to be returned.