Javatpoint Logo
Javatpoint Logo

Oracle GROUP BY Clause

In Oracle GROUP BY clause is used with SELECT statement to collect data from multiple records and group the results by one or more columns.

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.

Oracle GROUP BY Example: (with SUM function)

Let's take a table "salesdepartment"

Salesdepartment table:

oracle group by example 1

Execute this query:

Output

oracle group by example 2

The above example will show the total sales of every individual item.

Oracle GROUP BY Example: (with COUNT function)

Let's take a table "customers"

Here we are creating a table named customers. This table doesn't have any primary key.

Customer table:

oracle group by example 3

Execute this query:

Output:

oracle group by example 4

Oracle GROUP BY Example: (with MIN function)

Let?s take a table "employees"

Employees table:

oracle group by example 5

Execute this query:

Output:

oracle group by example 6

Oracle GROUP BY Example: (with MAX function)

In this example, we are using "employees" table that is given above.

Execute this query:

Output:

oracle group by example 7



Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA