Errors in the high-elevation query


This is one of the questions in the conditional aggregate
Find the percentage of high elevation airports (elevation >= 2000) by state from the airports table.

The error is given like this:
Find the percentage of high elevation airports by state.

Can anyone tell what's wrong with my code? Thank you!

select state, 100.0 * (sum(case when elevation >= 2000 then 1 else 0 end)/sum(elevation)) as percentage_high_elevation_airports
from airports
group by state;


An average would imply dividing by a count. The sum is in the numerator.


I don't quite get your point. Would you like to clarify it?


... / count(*)


Unfortunately, there is still something wrong after I tried your way....


The table won't be drawn if the SCT fails. The SQL might be right. Let's fiddle with the inputs and see how the SCT responds.

select state, 100.0 * sum(case when elevation >= 2000 then 1 else 0 end) / count(*)

What does this result in?


no from... gives me error again.
The case syntax gives me a binary result. Is it the error come from the sum(binary results)?


2 posts were split to a new topic: Stuck on high elevation


Be sure you haven't removed the rest of your code. The above is what goes before AS.


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