The RANGE function computes the range of returned values. 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.