Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
SQL Aggregate Functions Group By 
 

SQL Aggregate Functions Group By return the aggregate functions (like SUM) of the different numeric field for each individual group of column values.

 

SQL Aggregate Functions Group By

                         

SQL Aggregate Functions Group By return the aggregate functions (like SUM) of the different numeric field for each individual group of column values.

Understand with Example

The Tutorial grasp you with the use of 'SQL Aggregate Functions Group By'. In this example, we create a table 'Stu_Table'. The create table statement create a table 'Stu_Table'  

Create Table Stu_Table

create table Stu_Table(Stu_Id varchar(2), Stu_Name varchar(15), 
Stu_Class varchar(10),sub1 integer(2),sub2 integer(2),
sub3 integer(2),sub4 integer(2),sub5 integer(2));

Insert Value Into Stu_Table

The insert into statement add the records or rows to the table. 

insert into Stu_Table values(1, 'Komal', 10, 23, 34, 45, 56, 67);
insert into Stu_Table values(2, 'Ajay', 10, 34, 45, 56, 67, 78);
insert into Stu_Table values(3, 'Rakesh', 10, 23, 43, 45, 45, 34);
insert into Stu_Table values(4, 'Bhanu', 10, 56, 45, 67, 34, 54);
insert into Stu_Table values(5, 'Santosh', 10, 56, 67, 56, 67, 56);
insert into Stu_Table values(6, 'Tanuj', 10, 56, 45, 56, 56, 45);

Stu_Table

+--------+----------+-----------+------+------+------+------+------+
| Stu_Id | Stu_Name | Stu_Class | sub1 | sub2 | sub3 | sub4 | sub5 |
+--------+----------+-----------+------+------+------+------+------+
| 1      | Komal    | 10        | 23   | 34   | 45   | 56   | 67   |
| 2      | Ajay     | 10        | 34   | 45   | 56   | 67   | 78   |
| 3      | Rakesh   | 10        | 23   | 43   | 45   | 45   | 34   |
| 4      | Bhanu    | 10        | 56   | 45   | 67   | 34   | 54   |
| 5      | Santosh  | 10        | 56   | 67   | 56   | 67   | 56   |
| 6      | Tanuj    | 10        | 56   | 45   | 56   | 56   | 45   |
+--------+----------+-----------+------+------+------+------+------+

Query

The given below Query returns you the records enlisted in select statement and sum of different numeric field for each individual group of column values in the table 'Stu_Table'.

select stu_id, stu_name, sub1, sub2, sub3, sub4, sub5,
sum( sub1 + sub2 + sub3 + sub4 + sub5) as total 
from stu_table group by stu_id;

Result

+--------+----------+------+------+------+------+------+-------+
| stu_id | stu_name | sub1 | sub2 | sub3 | sub4 | sub5 | total |
+--------+----------+------+------+------+------+------+-------+
| 1      | Komal    | 23   | 34   | 45   | 56   | 67   | 225   |
| 2      | Ajay     | 34   | 45   | 56   | 67   | 78   | 280   |
| 3      | Rakesh   | 23   | 43   | 45   | 45   | 34   | 190   |
| 4      | Bhanu    | 56   | 45   | 67   | 34   | 54   | 256   |
| 5      | Santosh  | 56   | 67   | 56   | 67   | 56   | 302   |
| 6      | Tanuj    | 56   | 45   | 56   | 56   | 45   | 258   |
+--------+----------+------+------+------+------+------+-------+

                         

» View all related tutorials
Related Tags: sql mysql c query syntax ant reference sed display range limit number int tar start show if for poi ie

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.