表结构如下,
- Table "ytt.t1"
- Column | Type | Modifiers
- --------+-----------------------+-----------
- i_name | character varying(10) | not null
- rank | integer | not null
- t_girl=# select * from t1 order by i_name;
- i_name | rank
- ---------+------
- Charlie | 12
- Charlie | 12
- Charlie | 13
- Charlie | 10
- Charlie | 11
- Lily | 6
- Lily | 7
- Lily | 7
- Lily | 6
- Lily | 5
- Lily | 7
- Lily | 4
- Lucy | 1
- Lucy | 2
- Lucy | 2
- Ytt | 14
- Ytt | 15
- Ytt | 14
- Ytt | 14
- Ytt | 15
- (20 rows)
select *
from (select i_name, rank, row_number() over(partition by i_name) as row from t1) t
where row < =3