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, N1QL provides a negation operation which changes the sign of a value.
These arithmetic operators only operate on numbers. In N1QL, 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
SELECT sourceairport, destinationairport, ROUND(distance) AS DistanceInMiles,
ROUND(distance)*5280 AS DistanceInFeet
FROM `travel-sample`.inventory.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.