Introduction:

Here I will explain how to use group by in SQL Server  or To implement group by on column name in SQL server we need to use the whole expression in group by clause or Group by Clause implement with an aggregate function with Example.


Description:

 In Sql Server, we have group by clause for grouping the records of the database table according to our need in other words the SQL GROUP BY Clause is used to retrieve data grouped according to our need based on one or more columns. GROUP BY returns one record for each group. GROUP BY  Clause must be using an aggregate: COUNT, MAX, SUM, AVG, etc.

For Example:

Following example Without GROUP BY

SELECT S.id,S.Name,S.Mobile,S.address1,F.ammount AS amount FROM STUDENT AS S INNER 
JOIN Fee AS F ON S.id=F.StudentId

 

Result:




Above Example we use without group by  Select statement there are showing Name ,Mobile,Address1 Repeated. 

Following With GROUP BY Example:

SELECT S.id,S.Name,S.Mobile,S.address1,SUM(F.ammount) AS amount FROM
STUDENT AS S INNER
JOIN Fee AS F ON S.id=F.StudentId
group by S.id,S.Name,S.Mobile,S.address1


Result


Above Example we use group by select statement there are not showing Name, Mobile, Address1 Repeated.

Thanks.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like