Preview Content - log in or become a member

SQL GROUP BY

Video

Are you a member? Log In

Membership plans from just 6.00 USD*

* Currency: USD (US Dollar )
2500+ accounts so far

Plans:
Bronze
6.00 USD
Silver
9.00 USD
Gold
12.00 USD
6 Courses
T-SQL (3), SSRS (1), SSIS(1), Excel (1)
Watch Video
75 Mini Courses
T-SQL (34), SSRS (7), SSIS(16), + more
300+ videos and 300+ Articles
38
(part of
Courses)
Progress Tracking
21 Interview Q&As pages
T-SQL (8), SSRS (3), SSIS(4), Other (6)
Forum
11 Webinar Recordings
T-SQL (1), SSRS (9), Career(1)
1 DIY Project (beta)
70-461 Tests
Watch Video
60 days, 100% Money Back Guarantee
Instant Activation
Duration:
Bronze
Silver
Gold
Valid for: 1 month 6.00 USD
sign up
9.00 USD
sign up
12.00 USD
sign up
Valid for: 3 months
10% off
16.00 USD
sign up
24.00 USD
sign up
32.00 USD
sign up
Valid for: 6 months
20% off
28.00 USD
sign up
43.00 USD
sign up
57.00 USD
sign up
Valid for: 1 year
30% off
50.00 USD
sign up
75.00 USD
sign up
100.00 USD
sign up
Valid for: 2 years
40% off
86.00 USD
sign up
129.00 USD
sign up
172.00 USD
sign up
Valid for: lifetime
50% off
108.00 USD
sign up
162.00 USD
sign up
216.00 USD
sign up



Article

In this SQL tutorial I will cover SQL GROUP BY clause and give examples of how to use it. I will use SQL Server 2008 R2, but the examples in this tutorial should work with all SQL Server versions and some other databases. I will start with short and easy examples and explanations and move on to common group by questions that are slightly more involved.

Content:

 

SQL Group By Syntax

Below is group by syntax in the simpliest form:

SELECT FieldName

FROM TableName

GROUP BY FieldName

 

SQL Group By Example

Group By allows us to group rows together and additionally perform aggregate calculation which works on a group of rows. Let me first give you a simple example of what group by does using one field. I will use Customer table and group all customers by Country in other words I want to show all unique values that exist in Country Field, that is how group by works. See below example code with results (before and after)

Are you a member? Log In

Membership plans from just 6.00 USD*

* Currency: USD (US Dollar )
2500+ accounts so far

Plans:
Bronze
6.00 USD
Silver
9.00 USD
Gold
12.00 USD
6 Courses
T-SQL (3), SSRS (1), SSIS(1), Excel (1)
Watch Video
75 Mini Courses
T-SQL (34), SSRS (7), SSIS(16), + more
300+ videos and 300+ Articles
38
(part of
Courses)
Progress Tracking
21 Interview Q&As pages
T-SQL (8), SSRS (3), SSIS(4), Other (6)
Forum
11 Webinar Recordings
T-SQL (1), SSRS (9), Career(1)
1 DIY Project (beta)
70-461 Tests
Watch Video
60 days, 100% Money Back Guarantee
Instant Activation
Duration:
Bronze
Silver
Gold
Valid for: 1 month 6.00 USD
sign up
9.00 USD
sign up
12.00 USD
sign up
Valid for: 3 months
10% off
16.00 USD
sign up
24.00 USD
sign up
32.00 USD
sign up
Valid for: 6 months
20% off
28.00 USD
sign up
43.00 USD
sign up
57.00 USD
sign up
Valid for: 1 year
30% off
50.00 USD
sign up
75.00 USD
sign up
100.00 USD
sign up
Valid for: 2 years
40% off
86.00 USD
sign up
129.00 USD
sign up
172.00 USD
sign up
Valid for: lifetime
50% off
108.00 USD
sign up
162.00 USD
sign up
216.00 USD
sign up


Did you find this page useful?
+2  |  -0
(2 Votes)