आप 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);