SQL Math Question (How to Hack Hacker News step 4)

Hacker News Project

Step #4 asks you to basically select a math calculation, rather than accessing a table. And I found something I find odd. Why is the decimal point required?

SELECT (517 + 309 + 304 + 282) / 6366 returns 0.
SELECT (517 + 309 + 304 + 282) / 6366.0 returns .2218

Because you want a floating point number that you can convert to a %.

From the directions: " Then, we want to add these users’ score’s together and divide by the total to get the percentage."

1 Like

Okay, I think I get it now - it’s not that the division by a whole number is failing, it’s that if you divide by a whole number it will give an answer also rounded to the whole number?

1 Like

Yes it’s just integer division unless one of the numbers is already a different type.

And, as the question poses, you want a percentage of all those users’ scores. Thus, you’d divide by a point number.