sql

select top 10 id=identity(int,1,1), * into tab from x order by xxx desc 
select * from tab order by id

解决方案 »

  1.   

    select orders=(select count(*) from x a where a.xxx<=x.xxx),* 
    from x
    where (select count(*) from x a where a.xxx<=x.xxx)<=10
    order by orders
      

  2.   

    select distinct orders=(select count(*) from products a 
    where a.unitsinstock<=products.unitsinstock),* 
    from  products
    where (select count(*) from products a where a.unitsinstock<=products.unitsinstock)<=10
    order by  unitprice desc,orders 不行
      

  3.   

    你把order by 里全放到子查询里去不就行了,只留下orders 字段