+ 3
I don't understand using of group by
2 Réponses
+ 12
It simply groups the table by the chosen column. Useful info yes? =)
Like:
[NAMES] [NUMS]
Burak 18
Ally 7
Gina 99
Ally 3
Burak 3
Gina 2
*-------------------------*
Select names,nums
From exampletable
Group By names;
*-------------------------*
[NAMES] [NUMS]
Ally 7
Ally 3
Burak 18
Burak 3
Gina 99
Gina 2
And if you add an aggregate function, it becomes more handy:
*-------------------------*
Select names,sum(nums)
From exampletable
Group By names;
*-------------------------*
[NAMES] [NUMS]
Ally 10
Burak 21
Gina 101
Because in a larger table with more columns, it becomes more important that you have the totals for the right column.
For example: if you also add the city column, you could also group by city to see the totals for each city, instead of seeing the totals for names.
+ 5
Group By is used when using aggregate function. See it as, if you wanna aggregate something, you should be doing it on the basis of something. Like if you want to find the sum of 12 months of salary of each employee, you'll sum(salary) ... group by (employee id)
I hope this helps.