因为id可能不是连续的,所以不能用取得10<id<20的记录的方法。

有三种方法可以实现:
一、搜索前20条记录,指定不包括前10条
语句:
 
select top 20 *
from tbl
where id not in (select top 10 id from tbl)

二、搜索记录生成临时表,建立临时表的自增id。通过取得自增id的10<id<20的记录的方法取得所需数据
语句:
 
select identity(int,1,1) as id,* into #temp from tbl;
select *
from #temp
where id between 10 and 20

第二个方法实际上是两条语句,但你可以让他连续执行,就像一条语句一样完成任务。

三、第一种方法效率太低,得出第三种方法:
语句:
SELECT TOP 10 *
FROM (SELECT TOP 20 * FROM tblORDER BY id) as tbl2
ORDER BY tbl2.id DESC

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-11-07
  • 2022-12-23
  • 2021-11-03
猜你喜欢
  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2021-06-06
相关资源
相似解决方案