Simple Problem - Brain Freeze

P

Paul Smith

My data:

F1 F2 F3
a 0 20
a 4 40
a 0 40
b 1 15
b 0 50

I want to find the average for each value in F1 where there is a value in
column 1. Finding the sum of each required F2 is no problem, but when using
the Group By clause I cannot seem to eliminate the surplus F3s.

I want:

a 10
b 15

I get

a 25
b 65
 
A

Allen Browne

I think this is what you are after:
SELECT F1, Sum([F3]) / Sum([F2]) As AverageOfF3
FROM MyTable
GROUP BY F1
HAVING Sum([F2]) <> 0;

Or possibly you wanted:
SELECT F1, Sum([F3]) / Sum([F2]) As AverageOfF3
FROM MyTable
WHERE F2 <> 0
GROUP BY F1;

This assumes there are no nulls in any field to consider.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Export Query Automation 2
WCG Stats Tuesday 15 December 2020 1
Help Please 2
calculating a total amount 7
Average event between dates 5
adding fields 6
Search for maximum set of values 5
Calculate Diff Date? 3

Top