38
SELECT     AVG(variable) AS Expr1, SUM(variable) AS Expr2
FROM       ......

result for AVG is 2, but it is not true, it must be 2.95. What is the problem, any idea?

NetSide
  • 3,849
  • 8
  • 30
  • 41

1 Answers1

66

Try

Select
    AVG(Cast(variable as Float)),
    SUM(variable)
From
    Table
  • I would suggest using decimal instead of float. See this: https://stackoverflow.com/questions/1056323/difference-between-numeric-float-and-decimal-in-sql-server – Pouya BCD May 24 '18 at 18:53
  • 2
    @PouyaBCD Without knowing the precise use-case you can't just suggest to use decimals instead of floats. There exist perfectly valid use-cases for floats/doubles where using decimals would not work well (for example when you need huge ranges, for example numbers from 1e-18 to 1e+18). – jlh Dec 25 '18 at 15:22