Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

MySQL Group By Clause With Example

What is MySQL GROUP BY clause?

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:

SELECT 
    col1, col2,..., coln, aggregate_function(coli)
FROM
    table
WHERE
    your_where_conditions
GROUP BY col1 , col2,...,coln;

MySQL Queies Example

Below is the complete example of MySQL GROUP BY Clause. Use the below syntax to write your own MySQL queries.

SELECT 
    orderNumber,
    SUM(quantityOrdered * priceEach) AS total
FROM
    orderdetails
GROUP BY orderNumber;

MySQL GROUP BY Examples

MySQL GROUP BY with HAVING clause example

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

MySQL GROUP BY with HAVING Examples

The post MySQL Group By Clause With Example appeared first on FreeWebMentor.



This post first appeared on Programming Blog Focused On Web Technologies, please read the originial post: here

Share the post

MySQL Group By Clause With Example

×

Subscribe to Programming Blog Focused On Web Technologies

Get updates delivered right to your inbox!

Thank you for your subscription

×