4. Count(Case When)


#1

https://www.codecademy.com/en/courses/sql-table-transformation/lessons/conditional-aggregates/exercises/count-case-when?action=resume

I have completed this exercise however I'm confused about the then 1 part, I'm assuming it means count all the flights below 1000 ft and then skip one before ending the query? I'm probably completely off but can someone enlighten me? Thanks.

SELECT    state, 
    COUNT(CASE WHEN elevation < 1000 THEN 1 ELSE NULL END) as count_low_elevation_aiports 
FROM airports 
GROUP BY state;

*Using Chrome, Windows 10.


#2

Given this is a count, could it be simply adding 1 to the count when true? I'm guessing that else null is optional and could be removed in real life.


#3

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