Wrong "correct" result for 6. Combining aggregrates

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
Excercise link

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
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.)
<In this course, it often helps to include a screenshot of your whole web browser – that lets everyone see what you see. If you wish to include a screenshot, add it below this line.>

<If you wish to copy/paste in your code, you can use this next section. This will allow others to copy/paste your code for testing – something that they won’t be able to do with just a screenshot.>

```

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;

<do not remove the three backticks above>

Found my own question answered in this post. The title didn’t make me think it was related to my issue, but allas…

1 Like

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