I have a list of customers with an x and y co-ordinate for each between -50 and 50 for each. I need to calculate the number of customers in each 10x10 grid square but don't know how I can group customers by a range in two columns. The Customer table has a customerID, customer_x and customer_y column. I've managed to get the result for a single column using
SELECT 10 * ( customer_x / 10 ) AS start_range,
10 * ( customer_x / 10 ) + 9 AS end_range,
count(*) AS COUNT
FROM t_customer
GROUP BY customer_x / 10
I found this here, but can't work out how to get this working with a 2 dimensional range. I've started writing out a case for each grid-square using Select * from customer where (customer_x, customer_y) between (-50,-50) and (-50,-40)
and so on, but there's 100 in total and I'm assuming there's a more efficient way? I'm using SQLite3. Any help would be really appreciated.
I forgot to add, it actually only needs to show the grid square with the highest number of customers, so there may be a far easier way of doing this?