Bookmark Forum | Directory | Blog |

# SQL Tutorial >> SQL Group By Clause.

Back             Next

Now here in SQL Tutorial we return to the aggregate functions of SQL Group by clause. Remember we used the SUM keyword to calculate the total number of the employees records in our table of employees. Well, we need to do two things: First, we need to make sure we select the employees name as well as total salary. Second, we need to make sure that all the salary figures are grouped by month. The corresponding SQL syntax for SQL group by keyword is,

## Syntax for SQL Group By Clause

SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"

Let's illustrate using the following table,

Table Employees_Salary
 FirstName Month Salary Austin January 11000\$ Creston January 11000\$ Kate January 12000\$ Angela January 10900\$ Bobbi January 12000\$ Cute January 13000\$ Austin February 11100\$ Creston February 11100\$ Kate February 12100\$ Angela February 11000\$ Bobbi February 12200\$ Cute February 13300\$

## Example of SQL Group By Clause

SELECT Month, SUM(Salary)
FROM Employees_Salary
GROUP BY Month

Result:

 Month SUM(Salary) January 69900\$ February 70800\$

The SQL GROUP BY keyword is used when we are selecting multiple columns from a table (or tables) and at least one arithmetic operator appears in the SELECT statement. When that happens, we need to GROUP BY all the other selected columns, i.e., all columns except the one(s) operated on by the arithmetic operator. Hope this SQL Tutorial section is enough to explain SQL Group By Clause for beginners.

Back             Next

In order to link this page as Reference, click on below text area and pres (CTRL-C) to copy the code in clipboard or pres right click then copy the following lines after that past into your website or Blog.