The oracle group by clause is used in a select statement to gather data across multiple records and group the results by one
or more columns.
Syntax
The syntax for the oracle group by clause is
select expression1,expression2,......expression_n,
aggregate_function(expression)
from tables
where conditions
group by expression1,expression2,......expression_n;
Arguments or parameters
Expression1,expression2,.....expression_n that are not encapsulated within aggregate function and must be
included in the group by clause.
aggregate_function can be a function such as sum,count,min,max or avg function.
Tables are the tables that you wish to retrive records from.
There must be at least one table listed in the from clause.
Example:- Let us look at how we could use the group by clause with the MIN function.
SQL> select department_id,sum(salary) As "Total_salary_department_wise"
2 from employees
3 group by department_id;
DEPARTMENT_ID Total_salary_department_wise
------------- ----------------------------
100 51600
30 24900
1000 7000
999 9600
20 19000
70 10000
90 58000
110 20300
50 156400
40 6500
80 294900
DEPARTMENT_ID Total_salary_department_wise
------------- ----------------------------
10 4400
60 28800
13 rows selected.
or more columns.
Syntax
The syntax for the oracle group by clause is
select expression1,expression2,......expression_n,
aggregate_function(expression)
from tables
where conditions
group by expression1,expression2,......expression_n;
Arguments or parameters
Expression1,expression2,.....expression_n that are not encapsulated within aggregate function and must be
included in the group by clause.
aggregate_function can be a function such as sum,count,min,max or avg function.
Tables are the tables that you wish to retrive records from.
There must be at least one table listed in the from clause.
Example:- Let us look at how we could use the group by clause with the MIN function.
SQL> select department_id,sum(salary) As "Total_salary_department_wise"
2 from employees
3 group by department_id;
DEPARTMENT_ID Total_salary_department_wise
------------- ----------------------------
100 51600
30 24900
1000 7000
999 9600
20 19000
70 10000
90 58000
110 20300
50 156400
40 6500
80 294900
DEPARTMENT_ID Total_salary_department_wise
------------- ----------------------------
10 4400
60 28800
13 rows selected.
0 comments:
Post a Comment