While you’re at it, ROUND it. You’ll notice some of the decimal places are too far down (like 63.8768456) so the solution is to round them to the second decimal place. The thing with Rounding is to parenthesis the whole equation, then put the decimal place identifier after a comma at the end then, close parenthesis.

EXAMPLE:

SELECT state, ROUND(100.0 * sum(CASE WHEN elevation >= 2000 THEN 1

ELSE 0 END) / count(*), 2 ) AS percentage_high_elevation_airports FROM airports WHERE state IS NOT NULL GROUP BY state;

Now you might think it would be cleaner to ROUND the AS var ‘percentage_high_elevation_airports’ but this gives an error.

EXAMPLE:

SELECT state, 100.0 * sum(CASE WHEN elevation >= 2000 THEN 1 ELSE 0 END) / count(*) AS ROUND(percentage_high_elevation_airports,2) FROM airports WHERE state IS NOT NULL GROUP BY state;