Group By SQL Server function

Asked

Viewed 152 times

0

I’m a beginner in SQL Server, would like a help to understand the function Group By in a simple way. Both your concept and the way to use... for those who can help me thank you already!

1 answer

3


There are some functions like COUNT, MAX, MIN, SUM and AVG, in which they group some results, let’s assume you do:

select COUNT(nome) from pessoa

This will group all the names in a result, generating then the account the names, let’s assume that we have 4 names the result of the sum would be 4.

But let’s assume you wanted to count the same names, so you would

select COUNT(nome) from pessoa group by nome

So he’s going to group all the names equal and show the amount, so let’s assume that of these 4 there are two names equal john and the other two different, then the result would be 2 because of the two john and then we would have two more results 1 and 1 referring to the different names that remained.

See some examples

Example 1 Example 2 Example 3

Source

  • 1

    great example, it was much easier to understand how to use the function... thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.