SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Average not quite right
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

slydroe
Starting Member

17 Posts

Posted - 02/15/2014 :  02:11:01  Show Profile  Reply with Quote
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

Sweden
29910 Posts

Posted - 02/15/2014 :  03:12:00  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000