Skip to content
Advertisement

Print name of all activities with neither maximum nor minimum number of participants

How can i solve this question of hackerrank. I am quite confused an unable to move forward with this. enter image description here enter image description here

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);
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement