Arithmetic Operators
- reference
Arithmetic operations perform the basic mathematical operations of addition, subtraction, multiplication, division, and modulo within an expression or any numerical value retrieved as part of query clauses. Additionally, SQL++ provides a negation operation which changes the sign of a value.
These arithmetic operators only operate on numbers. In SQL++, arithmetic operators have their usual meaning. However, in any of these expressions:
|
Syntax
There are six different arithmetic syntaxes:
arithmetic-term ::= expr '+' expr |
expr '-' expr |
expr '*' expr |
expr '/' expr |
expr '%' expr |
'-' expr
Operator | Description |
---|---|
+ |
Add values. |
- |
Subtract right value from left value. |
* |
Multiply values. |
/ |
Divide left value by right value. |
% |
Modulo. Divide left value by right value and return the remainder. NOTE: Modulo is an integer operator and will use only the integer part of each value. |
- |
Negate value. |
Examples
To try the examples in this section, set the query context to the inventory
scope in the travel sample dataset.
For more information, see Query Context.
SELECT sourceairport, destinationairport, ROUND(distance) AS DistanceInMiles,
ROUND(distance)*5280 AS DistanceInFeet
FROM route
ORDER BY distance DESC
LIMIT 1;
[
{
"DistanceInFeet": 72906240,
"DistanceInMiles": 13808,
"destinationairport": "DFW",
"sourceairport": "SYD"
}
]
SELECT 5 % 3;
[
{
"$1": 2
}
]
SELECT 5.4 % 3.4;
[
{
"$1": 2
}
]
Related Links
Refer to Comparison Operators for numeric comparisons.