GROUP BY clause in SQL Server

GROUP BY Clause in SQL Server:-

                                                           A SELECT statement clause that divides the query result into groups of rows, usually for the purpose of performing one or more aggregations on each group. The SELECT statement returns one row per group.

For Example:-
                      We have EmployeeData table as shown below.
group by  in sql server
fig.1 EmployeeData Table

Lets find sum of salary of each city from EmployeeData table

Group By Query :-
group by
fig.2 Group By Clause

Explanation:-  This above result set shows sum of salary and grouped that data on the basis of city
as EmployeeData Table shown in fig.2.

As Alex and Zack is belongs to same city that is Amritsar so resultant sum of salary is (25000 + 15000= 40000).

Post a Comment