IBM Books

SQL Getting Started


Using Expressions to Calculate Values

An expression is a calculation or function that you include in a statement. The following statement calculates what the salaries for each employee in department 38 would be if each received a $500 bonus:

  
     SELECT DEPT, NAME, SALARY + 500
        FROM STAFF
        WHERE DEPT = 38
        ORDER BY 3

This result is:

     DEPT   NAME      3               
     ------ --------- ----------------
         38 Abrahams          12509.75
         38 Naughton          13454.75
         38 Quigley           17308.30
         38 Marenghi          18006.75
         38 O'Brien           18506.00

Note that the column name for the third column is a number. This is a system generated number, since SALARY+500 does not specify a column name. Later on this number is used in the ORDER BY clause to refer to the third column. Naming Expressions talks about how to give meaningful names to expressions.

You can form arithmetic expressions using the basic arithmetic operators for addition (+), subtraction (-), multiplication (*) and division ( /).

The operators can operate on values from several different types of operands, some of which are:


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]

[ DB2 List of Books | Search the DB2 Books ]