How can i solve this question of hackerrank. I am quite confused an unable to move forward with this.
here is what i have tried
SELECT DISTINCT ACTIVITY FROM FRIENDS, SELECT max(ACTIVITY) AS M WHERE M = (SELECT NAME FROM Activities);
Advertisement
Answer
You can use window functions
if your mysql version is 8 or above
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);