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.
| fig.1 EmployeeData Table |
Let's find the sum of the salary of each city from the EmployeeData table
Group By Query :-
| fig.2 Group By Clause |
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