602SQL Documentation Index  

Arithmetic Expressions (SQL)

You can use these binary operators in arithmetic expressions : + for addition, - for substraction, * for multiplication, / for division, DIV for division without a remainder a MOD for modulus. You can also use the unary operator minus - for inverse value.

Arithmetic operator priority is as normal:

  1. *,/,DIV and MOD (multiplication, division, division without a remainder and modulus)
  2. unary - , binary + a - (addition and substraction)
The priority may be changed using parenthesis.

Implicit conversion of expression operand types (numeric types) occurs when evaluating the expressions. Types are always converted to the next highest: TINYINT to SMALLINT to INTEGER to BIGINT to REAL.

602SQL variances

Example

Several combinations of arithmetic expressions are shown in the query:

SELECT Invoices.amount AS AMOUNT,
         (CURRENT_DATE-dat1-14) AS DAY_COUNT,
         (CURRENT_DATE-dat1-14)*0.01*amount AS PENALTY,
         amount+(CURRENT_DATE-dat1-14)*0.01*amount AS TOTAL,
         Companies.name AS NAME,
         Invoices.number AS IN_NUMBER
  FROM Invoices, Companies
  WHERE Invoices.company=Companies.number
    AND (Invoices.paid IS NULL AND 
         Invoices.dat1<=CURRENT_DATE-14 AND
         Invoices.type=2)