RANGE Function
The RANGE function returns the range of values for a numeric column expression argument.
It calculates the difference between the maximum and the
minimum values, as follows:
range(expr) = max(expr) - min(expr);
You can apply the RANGE function only to numeric
columns. The following query finds the range of ages for a population:
SELECT RANGE(age) FROM u_pop;
As with other aggregates, the RANGE function applies
to the rows of a group when the query includes a GROUP BY clause,
as the next example shows:
SELECT RANGE(age) FROM u_pop GROUP BY birth;
Because DATE values are stored internally as integers, you can use the RANGE function on DATE columns. With a DATE column, the return value is the number of days between the earliest and latest dates in the column.
NULL values are ignored unless every value in the column
is NULL. If every column value is NULL, the RANGE function
returns a NULL for that column.
Important: All computations for the RANGE function are performed
in 32-digit precision, which should be sufficient for many sets of
input data. The computation, however, loses precision or returns incorrect
results when all of the input data values have 16 or more digits of
precision.