I have two shapefiles that I want to spatial join (closest match), however, in the second shapefile I have records that are split by attribute X. I want the closest to records from each unique X record to shapefile nodes. i.e. the closest match usually pick the closest record from shapefile 2 to shapefile 1 nodes, but I want the closest from each X attribute value to each of shapefile 1 nodes.
An example would be: Shapefile 1: different schools around the city. Shapefile 2: Kids around the city Attribute X: Age category (1,2,3). I want the closest kid from each age category to every school.
How could this be done?