Home > DeveloperSection > Forums > Use of Group by and Having Clause in Sql Server
Ankit Singh

Total Post:341

Posted on    November-30-2015 9:29 PM

 Database SQL Server  SQL 

 1 Reply(s)
 441  View(s)
Rate this:
I want to use  Group by and Having Clause in sql server please help me.

aditya kumar Patel

Total Post:254

Posted on    November-30-2015 9:33 PM

Group By clause is used for grouping the records of the database table(s).This clause creates a single row for each group and this process is called aggregation. To use group by clause we have to use at least one aggregate function in Select statement. We can use group by clause without where clause.

The having  clause operates only on group rows of table(s) and act as a filter like as where clause. We use having clause to filter data that we get from group by clause. To use having clause we need to use group by clause first.

SELECT emp_name, SUM(Emp_sal) AS 'salary'
FROM Employee
GROUP BY emp_name
HAVING SUM(Emp_sal) >5000

Don't want to miss updates? Please click the below button!

Follow MindStick