GROUP BY is usually used along with the aggreagate functions to group one or more columns.
SQL GROUP BY Syntax
SELECT column_name, aggregate_function(column_name)
FROM table_name
GROUP BY column_name
Below is shown the "CommissionTBL" table:
Diego Roel |
3/27/2009 12:00:00 AM |
225.74 |
Diego Roel |
4/7/2011 12:00:00 AM |
325.25 |
Maria Anders |
5/9/2011 12:00:00 AM |
321.27 |
Thomas Hardy |
11/22/2009 12:00:00 AM |
421.73 |
Thomas Hardy |
3/1/2011 12:00:00 AM |
221.29 |
Yang Wang |
9/3/2009 12:00:00 AM |
445.73 |
SQL GROUP BY Example
To get the sum of the commission amount for a person,
we have used the GROUP BY "BAPerson" column.
Text Editor below has the SQL Query, click the "View Result" button, to see the result.
Select BAPerson, sum(Amount) as TotalAmount
from CommissionTBL
GROUP BY BAPerson
SQL in Text Editor: