请教一下mysql下有没有类似oracle的函数max over partition by的替代方案

请教一下mysql下有没有类似oracle的函数max over partition by的替代方案,第1张

-- 有的,可以子查询 来完成 分组取前N条数据

select * from table_name a where 

4>(select count(*) from table_name where gid=a.gid and col2>a.col2) 

order by a.gid,a.col2 desc

查询第三大值:select A, max(B) as thirdB from test

where B not in (select top 2 B from test order by B desc)

--这里就把第一、二大的数去掉了

group by A


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/8620133.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-18
下一篇 2023-04-18

发表评论

登录后才能评论

评论列表(0条)

保存