Need help with T-SQL script: How to average a field across records

I'm in need of a purely t-sql script that will average a single integer field across potentially tens of thousands of records. Note the following script:

select stitches from meistergram WHERE rundate BETWEEN '2011-01-01' AND '2011-12-31'

This script identifies the table (meistergram), the integer field (stitches) and qualifies the records to be averaged by a range of dates. Please use this as a basis for adding the additional t-sql required to return just the average of the stitches field. Thanks.
LVL 1
tcianfloneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Shaun KlineLead Software EngineerCommented:
Do you want an average across the entire record set? (select avg(stitches) from meistergram ..
Do you want an average grouped? More information is needed.
0
HainKurtSr. System AnalystCommented:
looks like he is asking for a simple avg

select avg(stitches) from meistergram WHERE rundate BETWEEN '2011-01-01' AND '2011-12-31'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tcianfloneAuthor Commented:
Shaun,
The requirement is to get an average of stitches across the entire set of records returned within the date range. As for grouping, I'm not familiar with how I might group the results.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ukerandiCommented:
select AVG(stitches) as 'Avarage' from meistergram WHERE rundate BETWEEN '2011-01-01' AND '2011-12-31' GROUP BY rundate
0
ukerandiCommented:
select AVG(stitches) ,rundate from meistergram WHERE rundate BETWEEN '2011-01-01' AND '2011-12-31' GROUP BY rundate,stitches
0
Shaun KlineLead Software EngineerCommented:
Please be aware that if rundate is a datetime field includes a time component, grouping by rundate will most likely not give you the result you are looking for:

SELECT CONVERT(varchar(10), rundate, 120) RunDate, AVG(Stitches) FROM meistergram WHERE rundate BETWEEN '2011-01-01' AND '2011-12-31 GROUP BY CONVERT(varchar(10), rundate, 120)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.