Guruji Point - Code You Want To Write

  • Home
  • Asp.Net
  • WCF
  • SQL
  • Type Script
  • AngularJS
  • Tech News
  • Blog
  • Earn Online

Wednesday, 28 December 2016

GROUP BY In SQL Server

 No comments   

Introduction

In this article i will explain about what is Group By and how to use this in Sql Server.

What Is

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. The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.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.

Practice

Here i am writing few sql queries  by using Group By clause. 

Synatax :

SELECT column_name, aggregate_function(column_name)
FROM table_name
WHERE column_name operator value
GROUP BY column_name;


Aggregate Function

This is an aggregate function such as the SUM, COUNT, MIN, MAX, or AVG functions.

using group By with Aggregate Functions :

Using SUM

 SELECT DepId, SUM(Salary) AS Total_Salaries
FROM Employees
GROUP BY DepId ;


Using COUNT

SELECT DepId, COUNT(*) AS TotalEmployees
FROM Employees
GROUP BY DepId ;


Using MAX

SELECT DepId, MAX(Salary) AS Max_Salaries
FROM Employees
GROUP BY DepId ;


Using MIN

SELECT DepId, MIN(Salary) AS Min_Salaries
FROM Employees
GROUP BY DepId ;




  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Email ThisBlogThis!Share to XShare to Facebook
Newer Post Older Post Home

0 comments:

Post a Comment

Facebook Updates

Guruji Point

Categories

Comman table Expression in SQL Dynamic Grid Row IQueryable in c# Learn AngularJS Scope_Identity() Use of indexes comma seperated string in sql row_number() and dense_rank() salary table structure. while loop in sql why do we need cursor why tuple used

About Us

This blog is about the Programming ,Tech News and some intresting facts related Contents. Here you can find fundamental and expert level topic of programming languages very practically related to C# , Asp.Net ,Sql-Server, JavaScript, Jquery, WebServices And also Web-Api, WCF ,WPF, Angular Js.

Contact Us

Email Us - gurujipoints@gmail.com
Contact- 8077657477

Reach Us

Copyright © Guruji Point - Code You Want To Write