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,
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$ |
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.