Case when and then || SQL

Case when and then || SQL

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.

Challenge table:

No alt text provided for this image

The challenge:

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'.

The solution:

No alt text provided for this image

Final output:

No alt text provided for this image

要查看或添加评论,请登录

Ahmed Khaleel的更多文章

社区洞察

其他会员也浏览了