create table tb (ptoid int,proclassid int,proname varchar(10))
insert tb
select 1,1,'衣服1'
union all
select 2,2,'衣服2'
union all
select 3,3,'衣服3'
union all
select 4,3,'衣服4'
union all
select 5,2,'衣服5'
union all
select 6,2,'衣服6'
union all
select 7,2,'衣服7'
union all
select 8,1,'衣服8'
select * from tb
ptoid proclassid proname
----------- ----------- ----------
1 1 衣服1
2 2 衣服2
3 3 衣服3
4 3 衣服4
5 2 衣服5
6 2 衣服6
7 2 衣服7
8 1 衣服8
(所影响的行数为 8 行)
select * from tb a where
(select count(*) from tb b where b.proclassid=a.proclassid and b.ptoid>a.ptoid) <2
order by proclassid
ptoid proclassid proname
----------- ----------- ----------
1 1 衣服1
8 1 衣服8
7 2 衣服7
6 2 衣服6
4 3 衣服4
3 3 衣服3
(所影响的行数为 6 行)