Javatpoint Logo
Javatpoint Logo

Oracle HAVING Clause

In Oracle, HAVING Clause is used with GROUP BY Clause to restrict the groups of returned rows where condition is TRUE.

Syntax:

Parameters:

expression1, expression2, ... expression_n: It specifies the expressions that are not encapsulated within aggregate function. These expressions must be included in GROUP BY clause.

aggregate_function: It specifies the aggregate functions i.e. SUM, COUNT, MIN, MAX or AVG functions.

aggregate_expression: It specifies the column or expression on that the aggregate function is based on.

tables: It specifies the table from where you want to retrieve records.

conditions: It specifies the conditions that must be fulfilled for the record to be selected.

having_conditions: It specifies the conditions that are applied only to the aggregated results to restrict the groups of returned rows.

Oracle HAVING Example: (with GROUP BY SUM function)

Let's take a table "salesdepartment"

Salesdepartment table:

oracle having example 1

Execute this query:

Output:

oracle having example 2

Oracle HAVING Example: (with GROUP BY COUNT function)

Let's take a table "customers"

Customer table:

oracle having example 3

Execute this query:

Output:

oracle having example 4

Oracle HAVING Example: (with GROUP BY MIN function)

Let's take a table "employees"

Employees table:

oracle having example 5

Execute this query:

Output

oracle having example 6

Oracle HAVING Example: (with GROUP BY MAX function)

Execute this query:

Output:

oracle having example 7
Next TopicOracle UNION




Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA