Using Group By clause in SQL server to view summarize data

Posted by Vikash under Sql Server category on | Points: 40 | Views : 1939
The GROUP BY clause summarizes the result set into groups as defined in the query by using aggregate functions. The having clause furthur restricts the result set to produce the data based on a condition.The syntax are

 SELECT column_list
from tale_name
where condition
[GROUP BY [ALL] expression [,expression]
[HAVING search_condition]

I have used adventureworks database for the following example.......

SELECT Title, 'Total Vacation Hours'=VacationHours, 'Total SickLeaveHours'=SickLeaveHours
FROM HumanResources.Employee WHERE Title in ('Recruiter','Stocker')
ORDER BY Title, VacationHours,SickLeaveHours

Comments or Responses

Login to post response