Bottom Article Ad

Ads Here

Monday, September 23, 2019

SQL GROUP BY clause

SQL GROUP BY Clause:-

The GROUP BY clause is used to divide the table into groups and return a row for each group. We use the GROUP BY clause with aggregate functions to produce summary values for each set. 

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.

Syntax:-

              Select column_names from table_name group by columnname1,columnname2....

Example:-

                      We have an EmployeeData table as shown below.
                     
group by  in sql server
fig.1 EmployeeData Table

Let's find the sum of the salary of each city from the EmployeeData table



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

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

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




















No comments:

Post a Comment