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
 General SQL Server Forums
 New to SQL Server Programming
 SQL Average not quite right

Author  Topic 

slydroe
Starting Member

17 Posts

Posted - 2014-02-15 : 02:11:01
Hi, I have this average query that doesn't quite return the correct value:

-----------
select AVG(Cast(Tally as decimal)) as Avr
from (
select count(distinct patientID) as Tally
-----------

Tally is a count of daily patients for a whole month (31 days), and Avr is the average of Tally (add all values from day 1-31, then divided by 31.

The query returns 20.032257, when I know for a fact that it should give me 19.129032 as I calculated it by hand, and also entered the tally into excel and used the average formula.

It seems to me that sql is getting confused maybe because of data type issues? I'm not sure... Help pls? :)

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2014-02-15 : 03:12:00
We can't tell from your query above.
It's truncated so we have no idea what is going on.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -