Introduction:
Ø Group by clause is used to group rows used with the SELECT Query.
Ø Group
by clause often used with Aggregate functions such as (SUM(), AVG(), MAX(),
MIN(), COUNT()) to group the results.
Ø Group
by must always follow the WHERE clause and precede the ORDER BY clause.
Syntax:
Example:
Table: Books
|
Book_Name |
Order_Date |
Orders |
|
SQL |
01-Dec-2000 |
2 |
|
DBMS |
05-Sep-2000 |
3 |
|
PL/SQL |
06-Oct-2000 |
4 |
|
SQL |
09-Sep-2000 |
3 |
|
SQL |
06-Oct-2001 |
2 |
|
DBMS |
22-Jun-2001 |
3 |
|
PL/SQL |
25-Jan-2002 |
3 |
|
SQL |
20-jul-2002 |
4 |
|
DBMS |
09-Nov-2003 |
4 |
Group by Clause:
Output:
|
Book_Name |
Sum(Orders) |
|
PL/SQL |
7 |
|
DBMS |
10 |
|
SQL |
11 |






No comments:
Post a Comment