这个可以用递归么
id name num
1 a 2.5
2 a 2.2
3 a 2.6
4 a 2.4
5 a 2.8
6 a 2.3
7 a 2.1
8 a 3.0
9 a 3.1
2 b 2.3
3 b 2.1
4 b 2.4
6 b 2.5
7 b 2.3
9 b 2.7
...
结果:往下大的保留
id name num
1 a 2.5
3 a 2.6
5 a 2.8
8 a 3.0
9 a 3.1
2 b 2.3
4 b 2.4
6 b 2.5
9 b 2.7
...
[解决办法]
create table #t(id int,name varchar(50),num float)
insert into #t
select 1,'a',2.5 union all
select 2,'a',2.2 union all
select 3,'a',2.6 union all
select 4,'a',2.4 union all
select 5,'a',2.8 union all
select 6,'a',2.3 union all
select 7,'a',2.1 union all
select 8,'a',3 union all
select 9,'a',3.1 union all
select 2,'b',2.3 union all
select 3,'b',2.1 union all
select 4,'b',2.4 union all
select 6,'b',2.5 union all
select 7,'b',2.3 union all
select 9,'b',2.7
begin
with t as
(select *,ROW_NUMBER() over(partition by name order by id) rownum from #t)
select id,name,num from t where not exists(select 1 from t t1 where t1.name=t.name and t.rownum-1=t1.rownum and t.num<t1.num )
end
drop table #t
AND id < t.id
AND [num] > t.[num] )
----------------结果----------------------------
/*
idnamenum
1a2.5
3a2.6
5a2.8
8a3.0
9a3.1
2b2.3
4b2.4
6b2.5
9b2.7
*/