Print name of all activities with neither maximum nor minimum number of participants
我已经尝试过以下查询,但给我错误:
select ACTIVITY
from (select ACTIVITY, count(*) as cnt,
max(count(*)) as max_cnt,
min(count(*)) as min_cnt
from FRIENDS GROUP BY ACTIVITY) FRIENDS
where cnt not in (max_cnt, min_cnt);
错误:第1行的错误1111(HY000):无效使用组功能MYSQL版本:8
大概,您没有运行MySQL 8.0(否则,您上一个问题给出的答案将是可行的。)>
在较早的版本中,您可以这样做:
select activity, count(*) no_activities
from friends
group by activity
having
count(*) > (select count(*) from friends group by activity order by count(*) asc limit 1)
and count(*) < (select count(*) from friends group by activity order by count(*) desc limit 1)
尝试以下操作,它应该使用MySQL 8.0
中的窗口功能。
您想要窗口功能: