Case when and then
Often it's useful to look at a numerical field not as raw data, but instead as being in different categories or groups.
You can use CASE
with WHEN
, THEN
, ELSE
, and END
to define a new grouping field.
Using the countries
table, create a new field AS geosize_group
that groups the countries into three groups:
- If
surface_area
is greater than 2 million, geosize_group
is 'large'
. - If
surface_area
is greater than 350 thousand but not larger than 2 million, geosize_group
is 'medium'
. - Otherwise,
geosize_group
is 'small'
.