如:从 group 为 1 、2 、3 的条件中查询 point 前 3 的项目的数据,这样就可以查询出 9 条数据了,能一条语句搞定吗?
1 ackoly 2022-11-15 19:43:06 +08:00 via iPhone 什么数据库,分析函数了解一下 |
2 optional 2022-11-15 19:49:07 +08:00 row_number over partition by 一下,再套个子查询或者 cte ,完事 |
![]() | 3 wolfie 2022-11-15 19:53:48 +08:00 ![]() |
4 kwh 2022-11-15 20:05:48 +08:00 ![]() select * from table where group=1 order by point desc limit 3 union select * from table where group=2 order by point desc limit 3 union select * from table where group=3 order by point desc limit 3 |
5 dqzcwxb 2022-11-15 20:26:03 +08:00 并行查三次是最终答案 |
7 bugfan 2022-11-15 20:45:12 +08:00 老哥这头像真帅~~ |