What does GROUP BY function actually do in SQL?

what it does is actually ,if it get similar results from a query then it will make the aggregate of every similar result and give a single row all in one like a group.

For example …

ID | NAME | AGE | ADDRESS | SALARY |
±—±---------±----±----------±---------+
| 1 | Ramesh | 32 | Ahmedabad | 2000.00 |
| 2 | Ramesh | 25 | Delhi | 1500.00 |
| 3 | kaushik | 23 | Kota | 2000.00 |
| 4 | kaushik | 25 | Mumbai | 6500.00 |
| 5 | Hardik | 27 | Bhopal | 8500.00 |
| 6 | Komal | 22 | MP | 4500.00 |
| 7 | Muffy | 24 | Indore | 10000.00 |
±—±---------±----±----------±---------+

Now, if you want to know the total amount of salary on each customer, then GROUP BY query would be as follows:

SQL> SELECT NAME, SUM(SALARY) FROM CUSTOMERS GROUP BY NAME;

This would produce the following result:

±--------±------------+
| NAME | SUM(SALARY) |
±--------±------------+
| Hardik | 8500.00 |
| kaushik | 8500.00 |
| Komal | 4500.00 |
| Muffy | 10000.00 |
| Ramesh | 3500.00 |
±--------±------------+