select *  from 表 a where (select count(*) from 表 b where a.bb=b.bb and b.cc<=a.cc)<=5

解决方案 »

  1.   

    select top 5 * from table
    order by cc desc,bb
      

  2.   

    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写的太繁琐了,哪位高人能写一个简练的,请不吝赐教