I will explain GROUP BY:
Look at this table
+----+----------+-----+
| id | salery |name |
+----+----------+-----+
| 1 | 2000 | Dave|
+----+----------+-----+
| 2 | 3000 | John|
+----+----------+-----+
| 3 | 1500 | John|
+----+----------+-----+
| 4 | 2000 | Dave|
+----+----------+-----+
| 5 | 4000 | Doe |
You can see that the table has the following records with duplicate names:
+----+----------+-----+
| id | salery |name |
+----+----------+-----+
| 1 | 2000 | Dave| <<<<
+----+----------+-----+
| 2 | 3000 | John| <<
+----+----------+-----+
| 3 | 1500 | John| <<
+----+----------+-----+
| 4 | 2000 | Dave| <<<<
+----+----------+-----+
| 5 | 4000 | Doe |
If you now wanna know the total amount of all customers
You can do it like this for every Name
SELECT SUM(salery)
FROM mytable
WHERE name = 'Dave';
Result should be 4000 (2000+2000)
For two names that should be a solution. But if you didnt know all names or your Database is much bigger
not very helpful.
For that we have GROUP BY.
SELECT name, SUM(salery)
FROM mytable
GROUP BY name;
This would produce the following result
+----+------------+-----+
| id | SUM(salery)|name |
+----+------------+-----+
| 1 | 4000 | Dave|
+----+------------+-----+
| 2 | 4500 | John|
+----+------------+-----+
| 3 | 4000 | Doe |
+----+------------+-----+
If you didnt type GROUP BY you would get the SUM from all SALERY Records and a Name of your first record