Quotes help make search much faster. Example: "Practice Makes Perfect"

Monday, July 18, 2016

SQL: Table Transformation Lesson 16 Sample Solution


Instructions:
Modify the case statement's such that when the elevation is less than 250, the elevation_tier column returns 'Low', when between 250 and 1749 it returns 'Medium', and when greater than or equal to 1750 it returns 'High'.

Be sure to alias the conditional statement as elevation_tier, in your query.

Sample Solution:
SELECT
    CASE
        WHEN elevation < 250 THEN 'Low'
        WHEN elevation BETWEEN 250 AND 1749 THEN 'Medium'
        WHEN elevation >= 1750 THEN 'High'
        ELSE 'Unknown'
    END AS elevation_tier
    , COUNT(*)
FROM airports
GROUP BY 1;

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Update 'When elevation BETWEEN 250 AND 1749...' to use 1750 instead. The way you have the solution will error. ;)

    ReplyDelete


This is an example of scrolling text using Javascript.

Popular Posts