Where Cause in Select Statement

  • We have a query that is performing a number of counts for a certain selection set and we would like to add a select statement that would take the average of an amount field but only for a certain option. So we have about 20 options and we only want to calculate the average amount for option 15.

    Thoughts?

  • tstagliano (8/8/2014)


    We have a query that is performing a number of counts for a certain selection set and we would like to add a select statement that would take the average of an amount field but only for a certain option. So we have about 20 options and we only want to calculate the average amount for option 15.

    Thoughts?

    Assuming the query uses GROUP BY, you could add a CASE statement within the AVERAGE aggregate. Something like this:

    AVG(CASE WHEN option = 15 THEN field_to_be_averaged ELSE NULL END)

    Steve (aka sgmunson) 🙂 🙂 🙂
    Rent Servers for Income (picks and shovels strategy)

  • Steve has posted what is probably the answer, but it would be much easier to help if you posted an example of the query.

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

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