Login

Username:

Password: 

Join us Now |  Forgot Password? | Forgot UserName?

SQL

Learn step by step



Sql Group By Clause

In SQL statement GROUP BY is used along with the SQL aggregate functions like SUM to provide means of grouping the result dataset by certain database table column(s).

Syntax

SELECT column1, column2
FROM table_name
WHERE [ conditions ]
GROUP BY column1, column2
ORDER BY column1, column2

To understand how to use GROUP BY Consider the following examples.

Employee Date Hours
Arpit jain 5/6/2014 4
Jai Soni 5/6/2014 8
Khushi Soni 5/6/2014 8
Jai Soni 5/7/2014 9
Arpit jain 5/7/2004 8
Pankaj Tak 5/7/2014 10
Ramesh Patel 5/8/2014 8
Pankaj Tak 5/8/2014 8
Jai Soni 5/8/2014 9
Ramesh Patel 5/9/2014 9


SELECT Employee, SUM (Hours)
FROM EmployeeHours
GROUP BY Employee

Output

Employee Hours
Arpit jain 12
Jai Soni 26
Khushi Soni 8
Pankaj Tak 18
Ramesh Patel 17


SELECT Date, SUM(Hours) as Hours
FROM EmployeeHours
GROUP BY Date

Output

Date Hours
5/6/2014 20
5/7/2014 27
5/8/2014 25
5/9/2014 9


Related Videos