Computing new columns

The SELECT clause can also contain expressions that compute/create new values from existing data. In fact, any kind of expression can be used in the SELECT list (if more than one item is returned, the items are inserted into an array). Here we show two examples demonstrating arithmetic expressions. The arithmetic operators: +, -, *, and / are supported.

To select the income column and perform a division operation which calculates monthlysalary:

sql-> SELECT id, lastname, income, income/12
AS monthlysalary FROM users;
 +----+----------+--------+---------------+
 | id | lastname | income | monthlysalary |
 +----+----------+--------+---------------+
 |  2 | Anderson | 100000 |          8333 |
 |  1 | Morrison | 100000 |          8333 |
 |  5 | Scully   | 400000 |         33333 |
 |  4 | Smith    |  80000 |          6666 |
 |  3 | Morgan   |   NULL |          NULL |
 +----+----------+--------+---------------+

5 rows returned 

To select the income column and perform an addition operation which calculates salarywithbonus:

sql-> SELECT id, lastname, income, income+5000
AS salarywithbonus FROM users;
 +----+----------+--------+-----------------+
 | id | lastname | income | salarywithbonus |
 +----+----------+--------+-----------------+
 |  4 | Smith    |  80000 |           85000 |
 |  1 | Morrison | 100000 |          105000 |
 |  5 | Scully   | 400000 |          405000 |
 |  3 | Morgan   |   NULL |            NULL |
 |  2 | Anderson | 100000 |          105000 |
 +----+----------+--------+-----------------+

5 rows returned