You are viewing a single comment's thread. Return to all comments →
SQL SERVER
Problem: AVG rounded to an integer value (the same data type as the values), so the decimal values are lost before casting to decimal.
Solution: CAST 'population' data type first, use AVG, then ROUND.
SELECT ROUND(AVG(CAST(POPULATION AS FLOAT)),3)
Seems like cookies are disabled on this browser, please enable them to open this website
Revising Aggregations - Averages
You are viewing a single comment's thread. Return to all comments →
SQL SERVER
Problem: AVG rounded to an integer value (the same data type as the values), so the decimal values are lost before casting to decimal.
Solution: CAST 'population' data type first, use AVG, then ROUND.
SELECT ROUND(AVG(CAST(POPULATION AS FLOAT)),3)