In MySQL you can use HAVING to reduce the number of rows.
SELECT
`group`, COUNT(*) NumOfNames
FROM
(SELECT
`group`,
name,
ST_DISTANCE_SPHERE(POINT('.$lon.', '.$lat.'), POINT(t1.lon, t1.lat)) / 1000 AS distance
FROM
t1
HAVING distance < 10) t2
GROUP BY `group`
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…