Java Reference
In-Depth Information
Table 7-3: Inventory
ID
Name
Description
Qty
Cost
1005
Chocolate Chip
Cookies
217
1.26
1006
Fig Bar
Cookies
162
1.57
1007
Sugar Cookies
Cookies
276
1.03
1008
Cola
Soda
144
0.61
1009
Lemon Soda
Soda
96
0.57
1010
Orange Soda
Soda
84
0.71
The first, and most obvious use of arithmetic operators is in the WHERE clause. The following example
uses the LESS THAN operator to identify items that are running low:
SELECT *
FROM INVENTORY
WHERE Qty < 24;
The preceding query will return the following result:
ID
Name
Description
Qty
Cost
1004
Oatmeal
Cereal
15
0.98
Creating calculated result fields
Another very useful application of arithmetic operators is to create a calculated result field as part of
the results returned from a query. For example, you can calculate a retail price by marking up a cost as
follows:
SELECT ID,Name,Description,Cost,Cost*1.6 AS Retail
FROM Inventory;
This query returns the additional column (or field) "Retail," as shown in Table 7-4 .
Table 7-4: Calculated Result Fields
ID
Name
Description
Cost
Retail
1001
Corn Flakes
Cereal
1.95
3.12
1002
Rice Krispies
Cereal
1.87
2.992
1003
Shredded Wheat
Cereal
2.05
3.28
1004
Oatmeal
Cereal
0.98
1.568
1005
Chocolate Chip
Cookies
1.26
2.016
Search WWH ::




Custom Search