本文介绍了没有最大或最小参与者数量的所有活动的打印名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何解决这个hackerrank的问题.我很困惑,无法向前推进.

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

这是我尝试过的

 SELECT DISTINCT ACTIVITY FROM FRIENDS,
 SELECT max(ACTIVITY) AS M
 WHERE M = (SELECT NAME FROM Activities);

推荐答案

如果你的mysql版本是8或以上,你可以使用窗口函数

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

这篇关于没有最大或最小参与者数量的所有活动的打印名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:47