In the MySQL, the GROUP BY Clause is a set of summary rows by the value of columns. This return the one row of each group. Below is the syntax for writing the MySQL GROUP BY Clause queries:
1 2 3 4 5 6 7 | SELECT col1, col2,..., coln, aggregate_function(coli) FROM table WHERE your_where_conditions GROUP BY col1 , col2,...,coln; |
Below is the complete example of MySQL GROUP BY Clause. Use the below syntax to write your own MySQL queries.
1 2 3 4 5 6 | SELECT orderNumber, SUM(quantityOrdered * priceEach) AS total FROM orderdetails GROUP BY orderNumber; |
1 2 3 4 5 6 7 8 9 10 11 | SELECT YEAR(orderDate) AS year, SUM(quantityOrdered * priceEach) AS total FROM orders INNER JOIN orderdetails USING (orderNumber) WHERE status = 'Shipped' GROUP BY year HAVING year > 2003; |
MySQL Query Result