Database Reference
In-Depth Information
Input
SELECT SUM(item_price*quantity) AS total_price
FROM orderitems
WHERE order_num = 20005;
Output
+-------------+
| total_price |
+-------------+
| 149.87 |
+-------------+
Analysis
The function SUM(item_price*quantity) returns the sum of all the expanded
prices in an order, and again the WHERE clause ensures that just the correct order
items are included.
Tip
Performing Calculations on Multiple Columns All the aggregate functions can be used
to perform calculations on multiple columns using the standard mathematical operators,
as shown in the example.
Note
NULL Values Column rows with NULL values in them are ignored by the SUM()
function.
Aggregates on Distinct Values
The five aggregate functions can all be used in two ways:
To perform calculations on all rows, specify the ALL argument, or
specify no argument at all (because ALL is the default behavior).
To only include unique values, specify the DISTINCT argument.
Tip
ALL Is Default The ALL argument need not be specified because it is the default
behavior. If DISTINCT is not specified, ALL is assumed.
 
 
Search WWH ::




Custom Search