SQL | Calculations exercise | Use a CASE statement to divide countries into groups

This exercise is provided to allow potential course delegates to choose the correct Wise Owl Microsoft training course, and may not be reproduced in whole or in part in any format without the prior written consent of Wise Owl.

Software ==> SQL  (198 exercises)
Version ==> Any version of SQL Server
Topic ==> Calculations  (7 exercises)
Level ==> Average difficulty
Subject ==> SQL training
Before you can do this exercise, you'll need to download and unzip this file (if you have any problems doing this, click here for help). Once you've done this:
  1. Go into SQL Server Management Studio;
  2. Open the SQL file you've just unzipped (you can press CTRL + O to do this); then
  3. Execute this script.

This will generate the database that you'll need to use in order to do this exercise (note that the database and script are only to be used for exercises published on this website, and may not be reused or distributed in any form without the prior written permission of Wise Owl).

You need a minimum screen resolution of about 700 pixels width to see our exercises. This is because they contain diagrams and tables which would not be viewable easily on a mobile phone or small laptop. Please use a larger tablet, notebook or desktop computer, or change your screen resolution settings.

Write a query to divide countries into these groups:

Continent id Belongs to Actual continent (for interest)
1 or 3 Eurasia Europe or Asia
5 or 6 Americas North and South America
2 or 4 Somewhere hot Africa and Australasia
7 Somewhere cold Antarctica
Otherwise Somewhere else International

Your query (based only on the tblCountry table) should show the following results:

Countries in order

The first few countries, sorted in reverse alphabetical order by your new column.


Save this query as Continental Drift, then close it down.

You can unzip this file to see the answers to this exercise, although please remember this is for your personal use only.
This page has 2 threads Add post
26 May 22 at 18:27

SELECT CountryName ,
WHEN (ContinentID = 1 or ContinentID =  3 ) THEN 'Eurasia'

WHEN (ContinentID = 5 or ContinentID =  6 ) THEN 'Americas'
WHEN (ContinentID = 2 or ContinentID =  4 ) THEN 'Somewhere hot'
WHEN (ContinentID = 7 ) THEN 'Somewhere Cold'
ELSE 'Somewhere else'

END AS CountryLocation
FROM tblcountry
ORDER BY CountryLocation DESC

25 Sep 19 at 15:48

Does anyone have the script for Continental Drift?

06 Oct 19 at 19:19

-- This should work---


SELECT [CountryName]
      WHEN [ContinentID] in ('1','3') then 'Eurasia'
      When [ContinentID] in ('5','6') then 'Americas'
      When [ContinentID] in ('2','4') then 'Somewhere hot'
      When [ContinentID] = 7 then 'Somewhere cold'
      ELSE 'Somewhere else' END as 'CountryLocation'
  FROM [WorldEvents].[dbo].[tblCountry]
  order by CountryLocation desc