Calculated results

You can use calculated values as part of a search condition. You can also display them for selected rows just as you display column values.

You can use an arithmetic expression in the SELECT clause or in the WHERE clause of the query:

The following two queries illustrate the use of an arithmetic expression in a SELECT clause.

This query:

SELECT DEPT, NAME, SALARY
FROM Q.STAFF
WHERE DEPT = 38

Produces this report:

DEPT NAME            SALARY
---- ----------  ----------
 38  MARENGHI      17506.75
 38  O'BRIEN       18006.00
 38  QUIGLEY       16808.30
 38  NAUGHTON      12954.75
 38  ABRAHAMS      12009.75

This query:

SELECT DEPT, NAME, SALARY/12 
FROM Q.STAFF
WHERE DEPT = 38

Produces this report:

 DEPT  NAME             EXPRESSION 1
------ ---------  ------------------
   38  MARENGHI      1458.8958333333
   38  O'BRIEN       1500.5000000000
   38  QUIGLEY       1400.6916666666
   38  NAUGHTON      1079.5625000000
   38  ABRAHAMS      1000.8125000000

Arithmetic operators:

Operator
Operation
+
add
-
subtract
*
multiply
/
divide

Within expressions, you can use column names (as in RATE*HOURS), columns and constants (as in RATE*1.07), and built-in functions (as in AVG(SALARY)/2). An expression can consist of numeric constants (such as 3*7) or character constants (such as SALARY + COMM).

When a table is created, each column in it is defined to hold a certain type of data. Arithmetic operations can be performed only on numeric data types, and the results of an operation can depend on the data types of the operands.

Example:

[ Previous Page | Next Page | Contents | Index ]