Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 AVG simliar ?

Author  Topic 

mike13
Posting Yak Master

219 Posts

Posted - 2015-01-08 : 06:07:35
a quick SQL question
im using the AVG function but is not giving me the desired result
example:
i got a 100 users that gave rating to a product
here are the values
rating - amount
5 - 516
4 - 89
3 - 33
2 - 20
1 - 11
AVG give me a 4
in my view it is clearly a 5

how can achief this?

thanks a lot

Ifor
Aged Yak Warrior

700 Posts

Posted - 2015-01-08 : 06:55:58
With integers the average is clearly 4.

If you want an average of 5 you will need to convert to a float and then round.

eg ROUND(AVG(Rating * 1.0), 0)
Go to Top of Page

viggneshwar
Yak Posting Veteran

86 Posts

Posted - 2015-01-08 : 08:51:08
Use Ceiling function to solve this Ceiling(AVG(Rating * 1.0))

Regards
Viggneshwar A
Go to Top of Page

mike13
Posting Yak Master

219 Posts

Posted - 2015-01-08 : 09:16:35
That worked! Thanks a lot
Go to Top of Page
   

- Advertisement -