SELECT ROUND(phot_g_mean_mag) AS bin, COUNT(*) AS n, AVG(SQRT(POWER(pmra,2)+POWER(pmdec,2))) AS pmavg FROM gaiadr1.tgas_source GROUP BY bin ORDER BY bin