Database Reference
In-Depth Information
▼
Analysis
Here
MIN()
returns the price of the least expensive item in the
products
table.
Tip
Using
MIN()
with Non-Numeric Data As with the
MAX()
function, MariaDB allows
MIN()
to be used to return the lowest value in any columns including textual columns.
When used with textual data,
MIN()
returns the row that would be first if the data were
sorted by that column.
Note
NULL
Values Column rows with
NULL
values in them are ignored by the
MIN()
function.
SUM()
is used to return the sum (total) of the values in a specific column.
Here is an example to demonstrate this. The
orderitems
table contains the
actual items in an order, and each item has an associated
quantity
. The total
number of items ordered (the sum of all the
quantity
values) can be retrieved
as follows:
▼
Input
SELECT SUM(quantity) AS items_ordered
FROM orderitems
WHERE order_num = 20005;
▼
Output
+---------------+
| items_ordered |
+---------------+
| 19 |
+---------------+
▼
Analysis
The function
SUM(quantity)
returns the sum of all the item quantities in an
order, and the
WHERE
clause ensures that just the right order items are included.
SUM()
can also be used to total calculated values. In this next example the total
order amount is retrieved by totaling
item_price*quantity
for each item: