Errors in the high-elevation query


#1

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;



#2

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


#3

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


#4

... / count(*)

#5

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


#6

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?


#7

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


#8

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


#9

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


#10

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