发布网友 发布时间:2022-04-29 18:12
共2个回答
懂视网 时间:2022-04-29 22:33
查询该表中,每组的最大两个数:
select a.* from hard a where (select count(*) from hard where aa = a.aa and bb > a.bb ) < 2 order by a.aa,a.bb desc
此处 2 即为n
(查询单表不分组的前n条最大数据: select DISTINCT bb from hard order by bb desc limit 2)
结果图:
原理剖析:
mysql分组查询前n条数据
标签:
热心网友 时间:2022-04-29 19:41
select a.* from 表 a where exists