Solved

Query question

Posted on 2014-10-13
2
69 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 45

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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.​
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

22 Experts available now in Live!

Get 1:1 Help Now