3. case when


#1


https://www.codecademy.com/en/courses/sql-table-transformation/lessons/conditional-aggregates/exercises/case-when?action=lesson_resume&link_content_target=interstitial_lesson


The code is giving output but it is showing that it is not matching the instructions. I have written the code according to the instructions but don't know what is missing.

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



select
		case 
    		when elevation < 250 then 'Low'
        when elevation between 250 and 1749
        then 'medium'
    
				when elevation >= 1749 then 'High'
        else 'Unknown'
				
        end as elevation_tier, elevation, count(*)
        from airports
        group by 1;


#2

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;

I think you should write '1750' instead of 'when elevation >= 1749' and get rid of 'elevation' in the line 'end as ~~'


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.