mysql 如何查询 top10 以外数据

2022 年 8 月 17 日
 CaptainD

好久不用 mysql 突然来个需求不会写了

1966 次点击
所在节点    问与答
8 条回复
luishou
2022 年 8 月 17 日
not in 应该能解决吧,子查询
TimePPT
2022 年 8 月 17 日
rank 下,然后过滤?
CaptainD
2022 年 8 月 17 日
@TimePPT @luishou 不是啥复杂条件,写了个 limit 10,XXX ,XXX 是很大的值
blueorange
2022 年 8 月 17 日
@luishou 子查询有点慢
cslive
2022 年 8 月 17 日
potatowish
2022 年 8 月 17 日
select * from t1
left join (select id, row_number() as rownum over (order by 排序字段 desc) from t)t2 on t2.id = t1.id
where t2.rownum > 10;
CaptainD
2022 年 8 月 17 日
@cslive 这个方式貌似只支持 sql server ?
@potatowish 后来也想到这个方式了,不过就是麻烦点,貌似我的方式也没毛病?
cslive
2022 年 8 月 17 日
@CaptainD mysql 支持,db2 支持,postgresql 支持,其它的没试过

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://v2ex.xtra.eu.org/t/873483

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX