SELECT TOP 100 * FROM TB ORDER BY ID DESCSELECT TOP 100 * FROM (SELECT TOP 200 FROM TB ORDER BY ID)AS T ORDER BY ID DESC如果没有ID请用IDENTITY 那样可以直接用ID BETWEEN 100 AND 200
N-M条记录 1. select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入 set rowcount n select * from 表变量 order by columnname desc 2. select top n * from (select top m * from tablename order by columnname) a order by columnname desc 3. 如果tablename里没有其他identity列,那么: select identity(int) id0,* into #temp from tablename取n到m条的语句为: select * from #temp where id0 >=n and id0 <= m如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行: exec sp_dboption 你的DB名字,'select into/bulkcopy',true 4. 如果表里有identity属性,那么简单: select * from tablename where identitycol between n and m
取后100条用什么 select top 100 order by id desc101到200 select top 100 from table where id not in(select top 100 from table)
select top 100 * from TableName --默认是取前100条 select top 100 * from TableName where order by ID Desc --取的是后100条
select * from tableName where ID between 100 and 200 --取得是101-200条记录
declare @id int select top 1 @id = aa.id from ( select top 100 * from table1 order by ID desc )aaselect top 100 from table1 where id > @id
select top 100 * from [Table] --取前100条 select top 100 * from [Table] where order by ID Desc --取后100条 SELECT TOP 100 * FROM (SELECT TOP 200 FROM [Table] ORDER BY ID) AS T ORDER BY ID DESC --取第101到200条
设ID为主键select top 100 * from table_1 where id not in (select top 100 id from table_1 order by id) order by id
select * from (select *,row_number() over(order by id) as rn from tb)p where rn between 101 and 200 --SQL2005
select identity(int) id,* into #temp from tb select * from #temp between id 101 and 200
那样可以直接用ID BETWEEN 100 AND 200
1.
select top m * into 临时表(或表变量) from tablename order by columnname -- 将top m笔插入
set rowcount n
select * from 表变量 order by columnname desc
2.
select top n * from
(select top m * from tablename order by columnname) a
order by columnname desc
3.
如果tablename里没有其他identity列,那么:
select identity(int) id0,* into #temp from tablename取n到m条的语句为:
select * from #temp where id0 >=n and id0 <= m如果你在执行select identity(int) id0,* into #temp from tablename这条语句的时候报错,那是因为你的DB中间的select into/bulkcopy属性没有打开要先执行:
exec sp_dboption 你的DB名字,'select into/bulkcopy',true
4.
如果表里有identity属性,那么简单:
select * from tablename where identitycol between n and m
select top 100 order by id desc101到200
select top 100 from table where id not in(select top 100 from table)
select top 100 * from TableName where order by ID Desc --取的是后100条
select top 1 @id = aa.id from
(
select top 100 * from table1 order by ID desc
)aaselect top 100 from table1
where id > @id
select top 100 * from [Table] --取前100条
select top 100 * from [Table] where order by ID Desc --取后100条
SELECT TOP 100 * FROM (SELECT TOP 200 FROM [Table] ORDER BY ID) AS T ORDER BY ID DESC
--取第101到200条
where rn between 101 and 200
--SQL2005
select * from #temp between id 101 and 200