Solved

Why the difference comes in excel and sql server while using avg function,

Posted on 2013-06-11
5
211 Views
Last Modified: 2013-06-11
The sample data is attached.
When i find the average using excel for set of observations the output varies in excel and sql server.Difference--in-Output.xlsx
0
Comment
Question by:searchsanjaysharma
  • 4
5 Comments
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39236946
it's (the result) is being treated as an integer in your query, but that's not true in Excel.
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39236947
see the difference this way perhaps:

select avg(data), avg(data*1.0) from table1

http://sqlfiddle.com/#!3/2efbb/2
0
 
LVL 13

Expert Comment

by:sameer2010
ID: 39236993
SELECT AVG(CAST(DataIn as REAL)) AS  FROM AVGTABLE
0
 
LVL 48

Accepted Solution

by:
PortletPaul earned 500 total points
ID: 39237021
yes, or any cast/convert that will provide higher precision, many to choose from...

select
  avg(data)
, avg(data*1.0)
, avg(cast(data as real))
, avg(cast(data as float))
, avg(cast(data as money))
, avg(cast(data as decimal(18,5)))
from table1
59  59.829545 59.829545454545 59.829545454545 59.8295  59.829545

Open in new window

0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 39237311
thanks & cheers, Paul
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question