select * ,identity(int) flag into #temp from QGMonthData where 1 = 2 insert #temp select * from QGMonthData order by id desc select LTPrior from #temp where flag = 2 最后别忘了 drop table #temp
--读取一张表中任意长度的连续记录 查询N-M条记录。 select IDENTITY(int,1,1) as iid,* into #temptable from yourtable select top M-N * from #temptable where iid>=NOR:select top M-N * from yourTable where id not in(select top N-1 id from table) ID为表具有唯一值的任何字段
倒数取两条,在这两中,顺序的第一条就是.select top 1 * from (select top 2 * from 表 order by id desc) tmp order by id
select top 2 * from table id not in (select top 1 id from table order by id desc ) order by id desc
select top 1 * from (select top 2 * from 表 order by id desc) tmp order by id
insert #temp select * from QGMonthData order by id desc
select LTPrior from #temp where flag = 2
最后别忘了
drop table #temp
查询N-M条记录。
select IDENTITY(int,1,1) as iid,* into #temptable from yourtable
select top M-N * from #temptable where iid>=NOR:select top M-N * from yourTable where id not in(select top N-1 id from table)
ID为表具有唯一值的任何字段