I have a table in SQL Server with a huge dataset containing accident data with columns such as:
id, accidentNumber, accidentDate, latitude, longitude
The requirement is to get the hotspots based on a selected date. is there a way I can group the accidents nearby each other and count them. to show that point x with 500 meter radius has N amount of accidents. and order them by the highest number of accidents.
the desired data set should look like
geopoint (lat,lng) | accient Count |
---|---|
##.#### , ##.##### | 8540 |
##.#### , ##.##### | 8134 |
##.#### , ##.##### | 7751 |
I already merged the latitude and longitude into a point
SELECT TOP 100
CASE
WHEN ((Latitude IS NOT NULL) AND (Longitude IS NOT NULL))
THEN geography::Point(Latitude, Longitude, 4326)
ELSE NULL
END AS geopoint,
accidentID, AccidentNumber
FROM
accidents
ORDER BY
accidentID
But I could not figure out how to group and count them.