Re: SQL to Bin one column and average another?



Slight correction ( colName not fieldName )
"Paul McAllister" <pmcall@xxxxxxxx> wrote in message
news:OWQTkGxcGHA.1260@xxxxxxxxxxxxxxxxxxxxxxx
Hello,

I have two columns of data, column1 and column2. I want to bin the values
in column1 according to a set of ranges, and average the data that is in
column2 for each of the bins. Not quite sure how to code this one up in
SQL.

I have successfully binned data to generate histograms in the past, but a
little lost on tihs one.
Sum(IIf(" &colName& ">=" &lowVal& " and " &fieldName& "<" &highVal",1,0))

I was thinking maybe 2 queries? The first to get the count and the
second to get the sum? Seems a little inefficient
Sum(IIf(" &colName& ">=" &lowVal& " and " &colName& "<" &highVal",1,0)) AS
binCount
Sum(IIf(" &colName& ">=" &lowVal& " and " &colName& "<"
&highVal",col2Name,0)) AS binSum

then

avg = binSum/binCount

I am offbase here?




.