4/8 count(case when...)


#1

what 's the different between using
count (case when elevation<1000 then 1 end )
and count (elevation<1000) ?

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


#2

Please post a link to the exercise. Thanks.


#3

Try this query and see it that helps give a clue. Seeing is better than any explanation I can come up with.

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

#4

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