gpt4 book ai didi

mysql - 以下 SQL 查询的正确解决方案是什么?

转载 作者:行者123 更新时间:2023-12-04 04:12:58 31 4
gpt4 key购买 nike

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

ERROR: ERROR 1111 (HY000) at line 1: Invalid use of group function MYSQL VERSION: 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 - 以下 SQL 查询的正确解决方案是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61397099/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com