use 数据库
select aa,bb,cc into #q from 表
group by bb,aa,cc
order by bb,cc desc
declare wys cursor for
select * from #q
open wys
declare @i int,@j int,@x int,@t nvarchar(10),@a int,@b nvarchar(10),@c datetime
select @i=1,@j=1,@x=(select count(*) from #q)
fetch next from wys into @a,@b,@c
set @t=@b
while @i<=@x
begin
if @t<>@b
select @t=@b,@j=1
if @t=@b and @j>5
delete from #q where current of wys
fetch next from wys into @a,@b,@c
select @i=@i+1, @j=@j+1
end
close wys
deallocate wys
select * from #q