I have a program that takes a point and creates circles of different sizes around the point. Then these circles are intersected with the locations of hospitals. I then get the number of the hospital out of that intersection.
Anyway here is the issue. I have a table that contains the hospital name and the distance of the circle that it was found in. The trouble is that the set is cumulative so if there was a hopital within 1 mile of the point then it gets in that set. If there is another hospital 3 miles from the point it gets that hospital AND the one that is 1 mile away. So when I get to say 100 miles away I have a lot of hospitals. But If I go 101 miles away I might only get 1 more hospital. I would like to have a query that lists the circle distance and tells me if there are any NEW hospitals in that circle that weren't present in all of the circles inside of it.
I can get this done one at a time like this:
select ring_id, Hosp from results where ring_id = 6
AND Hosp NOT IN
(select Hosp from results where ring_id = 5)
This compares 2 rings that are next to each other. This works great and tells me how many hospitals are in 6 only.
My problem is that I want to do this for ALL not just one at a time. Must I create a cursor and loop or can this be done as a SET?
Anyway here is the issue. I have a table that contains the hospital name and the distance of the circle that it was found in. The trouble is that the set is cumulative so if there was a hopital within 1 mile of the point then it gets in that set. If there is another hospital 3 miles from the point it gets that hospital AND the one that is 1 mile away. So when I get to say 100 miles away I have a lot of hospitals. But If I go 101 miles away I might only get 1 more hospital. I would like to have a query that lists the circle distance and tells me if there are any NEW hospitals in that circle that weren't present in all of the circles inside of it.
I can get this done one at a time like this:
select ring_id, Hosp from results where ring_id = 6
AND Hosp NOT IN
(select Hosp from results where ring_id = 5)
This compares 2 rings that are next to each other. This works great and tells me how many hospitals are in 6 only.
My problem is that I want to do this for ALL not just one at a time. Must I create a cursor and loop or can this be done as a SET?