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.
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.
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
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
Above Example we use group by select statement there are not showing Name, Mobile, Address1 Repeated.