Solved

Query question

Posted on 2014-10-13
2
77 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 49

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Suggested Solutions

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…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

735 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