mysql - 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.
here is what i have tried
SELECT DISTINCT ACTIVITY FROM FRIENDS,
SELECT max(ACTIVITY) AS M
WHERE M = (SELECT NAME FROM Activities);
解决方案
window functions
如果你的 mysql 版本是 8 或以上,你可以使用
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);
推荐阅读
- python-3.x - unicode 的 Python3 问题
- javascript - SEQUELIZE:有没有办法 .Sync( { alter: true} ) 保持关联表的数据一致?
- java - 将 OGG 读取为 LWJGL 3 OpenAL 的样本流
- c++ - D3D11 中的锁定矩形
- graphql - Strapi 嵌套,返回错误 Knex:获取连接超时。游泳池可能已经满了。你错过了一个 .transacting(trx) 电话
- java - 使用 JSON 将对象放入 recyclerview
- c# - Microsoft 'Identity Platform' 是否(轻松)与'(ASP.NET) Identity Framework' - MVC5 & .NET 4.7.2 集成?
- java - 如何在另一个班级中读出我的框架的 x 和 y?java范围
- caching - Jedis 和 Redisson 客户端之间的交叉兼容性
- flutter - 无法在颤动中调整行小部件的大小