I had to calculate the percentage of distance flown by DL per origin, but the code below only gives the correct percentage when it's 100%, like for BDL. In the cases where it's less it gives 0, even when it shouldn't be like for ATL (should be 66.9%). The site marks it correct though, and lets me continue.
Is there something wrong with my code or with CodeCademy?
(Re-added the code for total_flight_distance and total_delta_flight_distance from past excercises to see whether I was going nuts or not.)
SELECT origin, sum(distance) as total_flight_distance, sum(CASE WHEN carrier = 'DL' THEN distance ELSE 0 END) as total_delta_flight_distance, 100.0*(sum(CASE WHEN carrier = 'DL' THEN distance ELSE 0 END)/sum(distance)) as percentage_flight_distance_from_delta FROM flights GROUP BY origin;