Sum field1 and sum field2 then compare if field2>field1 etc

  • sum(Case when answera = 2 then 1 else 0 end) as answera

    sum(Case when answerb = 2 then 1 else 0 end) as answerb

    from sometable

    I'd like to then compare answera with answerb in the statement

    and show

    if the sum of answerb is greater than answera

    or answera is = answerb

    or missing data from answera and answerb

    This is what I need to calculate

    # who had a score of 4 both times or improved by 1

    # in 3 months with both pieces of information

    # missing one or both assessment results

    thanks,

    how do I go about doing that?

  • use a subquery like

    Select

    From

    (

    Select ...

    sum(Case when answera = 2 then 1 else 0 end) as answera

    sum(Case when answerb = 2 then 1 else 0 end) as answerb ) sq

    ....


    * Noel

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

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