Calculated fields can include mathematical functions and concatenation. Using concatenation in most flavors of DBMS’ look like this:
SELECT last_name || 'Home#: ' || home_phone,
FROM personal_info
ORDER BY last_name;
Output would looks something like this:
Gordon-Carroll Home#: 801-123-1234
Using MYSQL is slightly different:
SELECT CONCAT(last_name, 'Home#:', home_phone)
FROM personal_info
ORDER BY last_name;
Using an Alias to name your calculated field:
SELECT prod_id, quantity, item_price,
quantity*item_price AS expanded_price
FROM OrderItems
WHERE order_num = 2010;
This sample performs a mathematical equation on two fields and then stores the calculated field using an alias of “expanded_price”. This example shows how a db calculates multiple quantities of a product in a shopping cart to get the total cost spent on that item.