SELECT state,
100.00 * (sum (CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END) / count(*)) as percentage_high_elevation_airports
from airports
group by 1;
i have 2 theories: there are airports outside of USA in the list so the 1st raw is empty >>> i guess i need to ask if the state IS NOT NULL, then it should work…
the other is that the question is % of airports in this state > 2000ft / total # of airports in the country?? here i’m counting # airports in a state that are high to total # of airports in this state…
there is an entry with NULL value in state column. I removed it but still have an error msg
Select state,
100.00 * (sum (CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END) / count(*)) as percentage_high_elevation_airports
from (select state, elevation from airports
WHERE state IS NOT NULL)
group by 1
order by 1;
I use the ’ city’ column instead of ‘state’ because it references the number of airports…and I got it!
SELECT state,
100.0 * (SUM(CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END))/ COUNT (city) AS percentage_high_elevation_airports
FROM airports
GROUP by 1;