## Performing Mathematical CalculationsAnother frequent use for calculated fields is performing mathematical calculations on retrieved data. Let's take a look at an example. The • Input SELECT prod_id, quantity, item_price FROM orderitems WHERE order_num = 20005; • Output +---------+----------+------------+ | prod_id | quantity | item_price | +---------+----------+------------+ | ANV01 | 10 | 5.99 | | ANV02 | 3 | 9.99 | | TNT2 | 5 | 10.00 | | FB | 1 | 10.00 | +---------+----------+------------+ The • 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 MySQL 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.
Tip How to Test Calculations |