As for your βrightsβ, itβs not often that you see a question that includes βplease do not grant ...β. Does every bit help? In particular, since you have not really shown us what you know about STContains or STIntersects (or Filter() , for that matter) ...
Anyway, I had a zipcodes and storelocations database, so I renamed the tables / columns according to yours (I then have 6 535 CrimeLocatoins and 3,285 GeoShapes). I suppose you already understood this, but someone might find this useful ...
The following query returns the number of CrimeLocations in each GeoShapes.ShapeFile
SELECT G.Name, COUNT(CL.Id) FROM GeoShapes G INNER JOIN CrimeLocations CL ON G.ShapeFile.STIntersects(CL.LatLong) = 1 GROUP BY G.Name ORDER BY 2 DESC
This takes a lot of time (for example, 20 minutes), because I did not configure geospatial indexes, and my ShapeFiles have a high score counter, but it works successfully. If I wanted to limit the results, as you suggest:
SELECT G.Name, COUNT(CL.Id) FROM GeoShapes G INNER JOIN CrimeLocations CL ON G.ShapeFile.STIntersects(CL.LatLong) = 1 GROUP BY G.Name HAVING COUNT(CL.Id) = 500
Of course, you donβt want to hardcode the number 500 β so you can add the COUNT(*) FROM CrimeLocations subquery or a shared variable from a separate query.
Is it complicated enough?
Conceptdev Oct 11 '09 at 11:36 2009-10-11 11:36
source share