August 8, 2014 at 8:03 am
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?
August 8, 2014 at 8:42 am
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)
August 8, 2014 at 10:22 am
Steve has posted what is probably the answer, but it would be much easier to help if you posted an example of the query.
Jack Corbett
Consultant - Straight Path Solutions
Check out these links on how to get faster and more accurate answers:
Forum Etiquette: How to post data/code on a forum to get the best help
Need an Answer? Actually, No ... You Need a Question
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply