id,  type 两列,id为主键 ,想取同一type的前10条数据 怎么拼sql

解决方案 »

  1.   


    select *
    from tb t
    where id in (select top 10 id from tb where type = t.type order by id desc)
      

  2.   

    select *
    from tb t
    where id>=any (select top 10 id from tb where type = t.type order by id desc)
      

  3.   


    ;with aaa as
    (select row_number() over(partition by type order by id) as row,* from table)
    select * from aaa where row<=10
      

  4.   

    select tb.*  from tb where tb.id in (select top 10 tb1.id from tb tb1 where tb.type = tb1.type order by a,b )