Database Reference
In-Depth Information
The item_price column contains the per unit price for each item in an
order. To expand the item price (item price multiplied by quantity ordered),
you simply do the following:
Input
SELECT prod_id,
quantity,
item_price,
quantity*item_price AS expanded_price
FROM orderitems
WHERE order_num = 20005;
Output
+---------+----------+------------+----------------+
| prod_id | quantity | item_price | expanded_price |
+---------+----------+------------+----------------+
| ANV01 | 10 | 5.99 | 59.90 |
| ANV02 | 3 | 9.99 | 29.97 |
| TNT2 | 5 | 10.00 | 50.00 |
| FB | 1 | 10.00 | 10.00 |
+---------+----------+------------+----------------+
Analysis
The expanded_price column shown in the previous output is a calculated
field; the calculation is simply quantity*item_price . The client application
can now use this new calculated column just as it would any other column.
MariaDB supports the basic mathematical operators listed in Table 10.1. In
addition, parentheses can be used to establish order of precedence. Refer to
Chapter 7, “Advanced Data Filtering,” for an explanation of precedence.
Table 10.1 MariaDB Mathematical Operators
Operator
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
 
 
Search WWH ::




Custom Search