December 18, 2012

Group by in Sql Server


Group by Clause

Group by clause is used to group a data on a basis of specified columns.

  • Group by function is used with aggregate functions  like SUM , Count , Max , Min

structure of writing query using group by clause

Select <Column names>  , <any aggregate function>
from <Table Name>
where <filter Condition>
Group by <Column names> 



SELECT  DeptID , DeptName, max(salary) as Salary FROM Salary

where salary > 20000

group BY DeptID , DeptName

Above query will return Maximum salary of those departments where salary is greater than 20,000

No comments:

Post a Comment