"Next to" and "by" generally mean that the two places are adjacent to each other, while near just means they are close.
So in this example, imagine we are walking down the street and there is a school. Then, as we walk past the school, immediately there is a park. Then we keep walking, and there is a hospital.
So the park is next to or by both the hospital and the school.
The hospital is near the school, because they are not next to each other, but they are still close.