Vous pouvez utiliser les window functions
si votre version mysql est 8 ou supérieure
select activity from (select activity, count(*) as cnt,
max(count(*)) over () as maximum_cnt,
min(count(*)) over () as minimum_cnt
from friends group by activity) mytable
where cnt not in (maximum_cnt, minimum_cnt);