We wish to obtain the range (minimum and maximum) values of a column or a column.
Note that while it is most common to compute the range for numeric data, we may compute the range ( min and max values) for other data types to mean the following:
We wish to obtain the minimum (or maximum) value of a column of a table.
In this example, we wish to obtain the minimum and maximum values of the column col_2
for each
group where the groups are defined by the column col_1
.
SELECT col_1,
MIN(col_2) col_2_min,
MAX(col_2) col_2_max
FROM table_1
GROUP BY col_1
Here is how this works:
MIN()
and MAX()
from base R to identify the minimum and maximum value in a vector of
values respectively.MIN
and MAX
ignore NULL
values by default.