Task 17 - Output an integer


Return the price and average number of downloads grouped by price. Round the averages to the nearest integer.

Using round with no parameter,

SELECT price, ROUND(AVG(downloads)) FROM fake_apps
GROUP BY price;

yields this table

price    ROUND(AVG(downloads))
0.0      15762.0
0.99     15972.0
1.99     16953.0
2.99     17725.0
3.99     18742.0
14.99    19369.0

How would one remove the .0 from the output?

Maybe with

SELECT price, cast(ROUND(AVG(downloads)) as int)  FROM fake_apps
GROUP BY price;

Or maybe with this:


This still gives the dot zero, or am I missing something?. Leon’s solution is what I’ve been searching for all afternoon. Must have been looking at it all along in the docs and just didn’t put my finger on it.

google search
== discussions / opinions ==
sql round with no decimal site:stackoverflow.com
= http://stackoverflow.com/questions/12706689/sql-format-as-of-round-off-removing-decimals

1 Like

So round behaves like we expect, 4/5 rule, and convert behaves like floor?

No, you aren’t missing anything. I would normally test something before suggesting it but got a bit distracted this time. – it seemed sensible :slightly_smiling:

You and me, both. I’m not the quick study I once was, and get distracted way too easily. Trying to slow things down which is why I got enbroiled in the SQL course. That too eventually led to a dozen tabs open…

1 Like