Solved

Query question

Posted on 2014-10-13
2
74 Views
Last Modified: 2014-10-13
Hello,

I have a table that has the following columns: CountryCode, ClinicCode, Month, NumberOfPatients, AverageHeight

It holds the average height for the patients that have visited a clinic during a given month.

Example data:
CountryCode, ClinicCode, Month, NumberOfPatients, AverageHeight
10, 1, 2012-01-01, 10, 1.78
10, 1, 2012-02-01, 8, 1.77
10, 1, 2012-03-01, 12, 1.75
10, 2, 2012-01-01, 7, 1.74
10, 2, 2012-02-01, 6, 1.79
10, 2, 2012-03-01, 1, 1.95
11, 3, 2012-01-01, 10, 1.78
11, 3, 2012-02-01, 20, 1.82
11, 3, 2012-03-01, 11, 1.75
11, 4, 2012-01-01, 4, 1.75
11, 4, 2012-02-01, 16, 1.81
11, 4, 2012-03-01, 4, 1.84

Open in new window


I now need to create average statistics per County using the CountyCode column.

Since I know the number of patients involved in each average at each clinic I can work out the total height for a county and the total number of patients.  The average is then a simple divide of these two totals.

However I am not sure how the query should look:
Select
   CountCode,  
  Month,  
  “something” as CountryAverage
From MyTable 
Group by CountyCode, Month

Open in new window


How do I get the sum of the AverageHeight, and total number of patients per CountryCode and Month.

Is it sum( AverageHeight * NumberOfPatients) / Sum(NumberOfPatients) ?

Is it really that simple?
0
Comment
Question by:soozh
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 40376885
yes, that simple.
0
 
LVL 46

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 250 total points
ID: 40376904
Your question isn't about T-SQL but statistical formula.
I think it's how you told. Keep it simple ;)
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now