Subtract value in one record from another

  • Hello,

    I have a table of Sample Results. Each patient can have up to three records in this table. I differentiate them by using a variable called 'SampleType', which can be 1, 2 or 3. I also have a variable called 'HB' which holds a decimal value.

    I want to subtract the HB value in SampleType = 1 from the HB value in SampleType = 3 for a particular patient. I can use a variable called 'SubjectNumber' to identify a patient.

    Is there a way to perform this calculation?

    Many thanks for any help.

  • Hard to say w/o your schema and sample data but would this work?

    select (T1.HB-T2.HB) as CalcValue

    from SampleResults T1

    inner join SampleResults T2

    on T1.SubjectNumber = T2.SubjectNumber

    where T1.SampleType = 1

    and T2.SampleType = 3

    Mark

  • Mark Eckeard (11/26/2013)


    Hard to say w/o your schema and sample data but would this work?

    select (T1.HB-T2.HB) as CalcValue

    from SampleResults T1

    inner join SampleResults T2

    on T1.SubjectNumber = T2.SubjectNumber

    where T1.SampleType = 1

    and T2.SampleType = 3

    Mark

    Thank you Mark. That worked perfectly!

Viewing 3 posts - 1 through 2 (of 2 total)

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