I am doing a local statistic, similar to the the one described in a earlier question / answer:
SELECT a.tree_id, a.species, avg(b.age) as age_avg, count(*) as samples, a.geomFROM trees a LEFT JOIN trees bON ST_DWithin(a.geom, b.geom, 100) AND a.species = b.speciesWHERE a.age IS NULLGROUP BY...