How to get average value group by range

Hi, I am newly start to use rails and I have a problem.

score table is
Name scoreA scoreB
A 878 89
B 1000 98
C 1651 102
D 1045 78
E 2001 94
F 2800 112
G 3008 99

i want to have average value group by range.
like this result

scoreA ave_scoreB
0~1000 89
1001~2000 xx
2001~3000 xx
3001~ xx

It seems that the standard GROUP BY sql does not support this.
I can put the average value into temporay array by using 4 different

Does anyone has better solution than this?

many thanks!