id | num |
1 | 50.31 |
3 | 26.31 |
3 | 71.11 |
4 | 26.07 |
1 | 11.08 |
1 | 72.58 |
4 | 48.63 |
1 | 46.63 |
2 | 67.54 |
2 | 94.24 |
2 | 5.28 |
1 | 80.11 |
4 | 14.32 |
4 | 78.11 |
4 | 52.50 |
4 | 86.34 |
1 | 97.27 |
1 | 97.59 |
1 | 59.92 |
1 | 40.91 |
2 | 66.10 |
2 | 25.36 |
3 | 26.87 |
1 | 50.76 |
表的结构如上表,查询每个id的前3num。
select id,num from
(select id,num,row_number() over(partition by id order by num desc) as row_num from {table}) a
where row_num <= 3;