Solved

Query question

Posted on 2014-10-13
2
78 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

739 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