Why SUM(Low_wage_jobs) / SUM(Total) always results in 0? (254-8: Querying Virtual Columns With the HAVING Statement)

Hi everyone,

Could anyone please help me understand the logic behind this?

How come SUM(Low_wage_jobs) / SUM(Total) results in 0? The result should be the Share_low_wage shown below.

You can do the maths, if you divide 60116 / 357130, the result is 0.1683308…

In fact, that’s the way I tried to solve it at first because it didn’t make sense for me to divide an average by another.

Screen Link:

My Code:

SELECT Major_category, SUM(Low_wage_jobs), SUM(Total), 
       AVG(Low_wage_jobs) / AVG(Total) AS Share_low_wage, 
       SUM(Low_wage_jobs)/ SUM(Total) AS test
    FROM new_grads
    GROUP BY Major_category
    HAVING Share_low_wage > 0.1;

What I expected to happen:
Column “test” should display the same results of column Share_low_wage

What actually happened:
Column test results in 0

Thank you in advance!

This is explained in Step 12 of the Mission. I would recommend going through it in detail.

Also, for any future posts, also make sure to add the link to the Mission to your post. It helps add the right context and makes it easy to directly access the Mission in order to be able to provide the best possible answer.

1 Like