I feel like this could be done more efficiently in SQL through aggregation, but couldn't quite find what I was looking for.

If you have some idea how to do it, I think it'd be more efficient (the worry is in case the # of facilities does get large).  If you don't, no worries--we could address it if it ever became a real concern.