In this tutorial you will learn about the MySQL Group By Clause and its application with practical example.
The GROUP BY statement is used to group the result set returned by SELECT statement by one or more columns.We can use GROUP BY to group values of a column we can perform any calculations on that column. COUNT, SUM, AVG etc. function can be applied on the grouped column.
Table Of Contents−
Consider below “emp_info” table
empID | empName | sale |
---|---|---|
1 | Mark | 1000 |
2 | Max | 1000 |
3 | Mark | 1000 |
4 | Mark | 1000 |
5 | John | 1000 |
1 2 |
SELECT EMPNAME,SUM(SALE) FROM emp_info GROUP BY EMPNAME |
Output:
empName | sale |
---|---|
Mark | 3000 |
Max | 1000 |
John | 1000 |