Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

query to find average age and percentage of patients with something Expand / Collapse
Author
Message
Posted Thursday, May 9, 2013 3:01 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 6:23 AM
Points: 15, Visits: 50
Hi All. Below is an example table of what i need to query out of:

Patient Name, Patient No., Age, Cancer, Consultant, Operation

Joe Bloggs 123 25 Yes Dr Smith Back
Joe Bloggs2 321 29 NO Dr loggs Spine


I need a simple query to find the average age from the table and also to find the percentage of patients with cancer and percentage of patients without cancer . thanks
Post #1450943
Posted Thursday, May 9, 2013 3:19 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:45 AM
Points: 5,388, Visits: 9,972
Is this homework? Please show us what you've tried so far, and we'll see if we can help with where you're going wrong?

John
Post #1450953
Posted Thursday, May 9, 2013 4:28 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 6:23 AM
Points: 15, Visits: 50
sorry ive got this working. what i need now is code to find the number of operations per consultant soo it looks like this:

COnsultant Total no. of operations

Dr Bloggs 23
Dr Doe 20
Sr Smith 14

i have the following code

select COUNT(operation) as [number of operations]
from tablenamewhere (Consultant = 'Dr Bloggs' or Consultant = 'Dr Smith' or Consultant = 'Dr Doe') but this is wrong.
Post #1450997
Posted Thursday, May 9, 2013 4:40 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 9:45 AM
Points: 5,388, Visits: 9,972
You need to use a GROUP BY clause.

John
Post #1451003
Posted Thursday, May 9, 2013 4:44 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 6:23 AM
Points: 15, Visits: 50
ive added the group by but it results to this
no of operations
1
2
5
7


when i need it to result like this:

Consultant name No. of operations

Dr Smith 3
Dr Bloggs 5
Dr Doe 20
Post #1451008
Posted Thursday, May 9, 2013 4:47 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 8:22 AM
Points: 689, Visits: 2,788
prb88 (5/9/2013)
ive added the group by but it results to this
no of operations
1
2
5
7


when i need it to result like this:

Consultant name No. of operations

Dr Smith 3
Dr Bloggs 5
Dr Doe 20


Just a guess:
select 
COUNT(operation) as [number of operations]
,Consultant
from
tablename
where (Consultant = 'Dr Bloggs' or Consultant = 'Dr Smith' or Consultant = 'Dr Doe')
group by
Consultant



==========================================================================================================================
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe
Post #1451011
Posted Thursday, May 9, 2013 4:51 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, July 17, 2013 6:23 AM
Points: 15, Visits: 50
cheers Andy helped a lot
Post #1451015
Posted Friday, May 10, 2013 4:44 AM


Say Hey Kid

Say Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey KidSay Hey Kid

Group: General Forum Members
Last Login: Today @ 8:22 AM
Points: 689, Visits: 2,788
No Probs

==========================================================================================================================
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila. Mitch Ratcliffe
Post #1451512
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse