SELECT state, 100.0 * SUM(CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END) / COUNT(*) as percentage_high_elevation_airports
FROM airports
GROUP BY state;
Why does the query above work and the query below not?
SELECT state, 100.0 * (SUM(CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END) / COUNT(*))as percentage_high_elevation_airports
FROM airports
GROUP BY state;