表A中有一字段ID(int)是自动编号,现在查询ID从31到45条记录(注ID可能不连续)
请问sqlserver的sql语句怎么写???

解决方案 »

  1.   

    select * from A where id between 31 and 45
    是这个意思吗?
      

  2.   

    编号有大小关系
    select top 15 *
    from (select top 45 * from A order by ID )t order by ID desc
      

  3.   

    select *
    from (select *,row_number()over(order by ID) row from a)t where row between 31 and 45或
    select top 15 * from A where ID not in(select top 30 ID from A) order by ID
      

  4.   

    select *
    from (select *,row_number()over(order by ID) row from a)t where row between 31 and 45或
    select top 15 * from A where ID not in(select top 30 ID from A order by ID) order by ID--没排序时
    select top 15 * from A where ID not in(select top 30 ID from A )--用表的默认排序时
      

  5.   

    select * 
    from (select *,row_number()over(order by ID) row from a)t where row between 31 and 45 
    这句看不懂,能给解释一下吗?还有
    select top 15 * from A where ID not in(select top 30 ID from A order by ID) order by ID 
    为什么要排序呢?