query to aggregate medstats users