window functions
を使用できます mysqlのバージョンが8以上の場合
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);