query to find average age and percentage of patients with something

  • 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

  • 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

  • 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.

  • You need to use a GROUP BY clause.

    John

  • 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

  • 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

  • cheers Andy helped a lot 😉

  • 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

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply