Take the 2-minute tour ×

As I iterate through the rows of a mysql table, there are 2 values in each table (x,y) that I need to see what interval those two values fall between.

For example if x=-21.1 and y=52.4, x would be in the -30..-20 interval and y would be in the 50..60 interval.

So based on these intervals, I would have a hash or something containing that interval combination (-30..-20 and 50..60) and increment it by one. Then I would go through the rest of the rows in the mysql table and do the same so I have a count of all occurances of the interval combinations.

There will be 36X36 combinations (interval -180..180, divided in 10s). I think this is supposed to be done by using multidimensional hashes, but I'm not sure. Can anyone help me out?

share|improve this question

1 Answer 1

How about doing it in MySQL itself?

SELECT FLOOR(x/10)*10, FLOOR(y/10)*10, COUNT(*)
FROM yourTable
share|improve this answer
Thank you so much! This works quite well and easily implementable in my Perl code :) –  user1001715 Oct 18 '11 at 18:26

Your Answer


