MySQL SUM Function

Introduction to MySQL SUM Function

This MySQL tutorial explains how to use the MySQL SUM function with syntax and examples. The MySQL SUM function returns the summed value of an expression.

SUM() Syntax

SELECT SUM(column_name)
FROM table_name
WHERE condition;

To understand SUM function, consider an “OrderDetails” table, which is having the following records:

SELECT * FROM OrderDetails;
OrderDetailIDOrderIDProductIDQuantity
16446
124412
26457
35788
344412
424610
773210
865918

The following MySQL statement finds the sum of the “Quantity” fields in the “OrderDetails” table:

SELECT SUM(Quantity) AS TotalQuantity
FROM OrderDetails;
TotalQuantity
83

Leave A Reply

Your email address will not be published.

Comment moderation is enabled. Your comment may take some time to appear.