CYBER WEEK - EXTRA SAVINGS EVENT # 255-6 Why isn't SUM() needed?

My Code:

``````SELECT CAST(SUM(Sample_size)AS FLOAT)/SUM(Total) AS avg_ratio
``````

What I expected to happen:
Ratio of sample size to total

What actually happened: ??? The correct answer was

``````SELECT AVG(CAST(Sample_size AS FLOAT)/Total) AS avg_ratio
``````

I am unsure why I do not need the SUM function.

1 Like

Hi @daniellij,

I think there might be a confusion in the question. The question wants the average ratio between `Sample_size` and `Total` for all of the majors.

Imagine you are getting candies for Halloween for the kids, and here are some random possible scenarios:

scenario number_of_kids number_of_candies
1 5 10
2 8 20
3 10 25
4 12 30

So the equivalent question as the mission would be, what’s the average number of candies a child gets, in all of these scenarios?

Let’s not worry about splitting the candies in this case, and hope the kids will share equally… The equation to answer the question would be the average of the number of candies a child get in each scenario, which is: `((10/5)+(20/8)+(25/10)+(30/12))/4`, in SQL language, it’s `AVG(CAST(number_of_candies AS FLOAT)/number_of_kids)`.

Your solution to sum each column and then divide by one another is kinda like seeing all scenarios as a whole and related, but they are actually individual cases.

Btw, I remember struggling through the whole SQL section of the path and the wordings were more often than not, confusing as ■■■■… It does get better though, just need to take breaks more often. Hope this helps. 6 Likes