SQL GROUP BY Statement | Oracle GROUP BY Clause examples

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

The GROUP BY statement is used in conjunction with the aggregate functions like SUM to provide means of grouping the result by certain table column or columns.

Syntax:

SQL> SELECT columnName, aggregate_function(columnName)
FROM tableName
WHERE
GROUP BY columnName

Examples :

Step 1: Create a table ‘MyTable’ as below.

SQL> create table MyTable (name varchar2(100),address varchar2(500),marks number);

Table created

Step 2: Insert few rows to ‘MyTable’.

SQL> insert into  mytable values ('Chris','Add1',1);
SQL> insert into  mytable values ('John','Add2',2);
SQL> insert into  mytable values ('John','Add2',3);
SQL> insert into  mytable values ('John','Add2',4);
SQL> insert into  mytable values ('Chris','Add1',5);
5 rows inserted

Step 3: Now let us calculate the total marks for Chris and John using GROUP BY Clause.

SQL> select name,SUM(marks) from mytable GROUP BY name;
NAME                                         SUM(MARKS)
John                                                        9
Chris                                                       6

Technorati Tags:
, ,

0 Flares Twitter 0 Facebook 0 Google+ 0 LinkedIn 0 Buffer 0 Email -- Filament.io 0 Flares ×

2 thoughts on “SQL GROUP BY Statement | Oracle GROUP BY Clause examples

  1. Pingback: COUNT() Function in SQL ,Using COUNT(*) and COUNT(1) in Oracle | SQL and PLSQL

  2. Pingback: SQL: MAX Function | Oracle Max() examples | SQL and PLSQL

Leave a Reply

Your email address will not be published. Required fields are marked *

Paged comment generated by AJAX Comment Page