Group By :
It is used to group the result-set by one or more column. It is used in conjunction with aggregate functions provided by Structured Query Language . If order by is used then Group By must come before Order By clause.
Syntax1:
SELECT column1,column2,...,columnN FROM tablename WHERE conditions GROUP BY columnname;
Syntax2:
SELECT column1,aggregate-function(columnName) FROM tablename WHERE conditions GROUP BY columnname;
Example:
SELECT City, SUM(Salary) FROM Employee GROUP BY City;
The above query will fetch city and sum of salary who are grouped by city. It means that sum of salaries will be city wise.
0 Comment(s)