Subqueries P5 (Question about nesting)

select cast(avg(Sample_size) as float)/cast(avg(Total) as float)) avg_ratio from recent_grads
select AVG(cast(Sample_size as float)/cast(Total as float)) avg_ratio from recent_grads

My answer - I think this makes more sense logically to nest AVG directly than nesting the entire formula in AVG, there is a very slight difference in the result, is my code wrong?

Hey there Genesix,

Before I address your question, if I may, I wanted to give you some quick feedback. If you’re able to include a link to the URL your question relates to, it will help your fellow community members quickly get context on your question and increase the likelihood of a quick reply. For others reading along with this thread, this particular question seems to relate to this URL:

I also think the first code you shared may have an extra ) in it — I got an error when I first tried to run it.

I get the following results from the two code snippets:

  • 0.009091184125182722
  • 0.009085896594349793

As you point out, there is a very slight difference between these numbers. This is just due to the differences in rounding from the two different approaches.

I would say that your code is a reasonable way to answer this question - unfortunately, the limitations of the Dataquest answer checker (which compares the two numbers for exact equality) means that it won’t pass on our system, but I don’t think that should take anything away from your approach.

1 Like

Thanks for your help! Will include the links in the futures. Cheers!