select top 2 * 
from b1
where a1=1
order by a3 desc

解决方案 »

  1.   

    取的是a1=1的a2分组后,最大的a3值.
      

  2.   

    declare @t table(id int,a1 int,a2 int , a3 int)
    insert @t
     
    select 1,    1 ,     1,     4 union all
    select 2,    1 ,     2,     5 union all
    select 3,    1 ,     2,     9 union all
    select 4,    1 ,     1,     8 union all
    select 5,    2 ,     4,     1select * from @t a 
    where not exists (select * from @t where a1=a.a1 and a2=a.a2 and a3>a.a3) and a1=1
      

  3.   

    select max(a3) as maxa3, a2 from table1 where a1=1 group by a2
      

  4.   

    select top 2 * from 表 where a1='1' order by a3 desc