select top 1 * from 表名 where id not in (select top 2 * from 表名)
select top 1 * from 表名 where id not in (select top N-1 * from 表名)--上面的语句中,N是代表第N条,用具体的数字代替N-1就得到相应的记录
select top 1 * from (select top 3 * from tb ) a order by createtime desc
select top 1 * from ( select top n * //n表示你要查询的第n条记录,比如取第3条记录,n=3 from table order byu desc )
select top 3 * from 表 或 select * from 表 where name='C'
select top 1 * from ( select top 3 * from table order by createtime ) a order by createtime desc
查询N-M条记录:select IDENTITY(int,1,1) as iid,* into #temptable from yourtableselect 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为表具有唯一值的任何字段
谢谢大家的回复,我已经了解了TO yjdn(无尽天空) select top 1 * from TABLE where ID not in (select top 2 * from TABLE) 有问题,where ID not in (select top 2 * from TABLE) 在not in列表中只能指定一个字段ID,但是select top 2 * from TABLE 查出的是所有字段TO long0104() select top 3 * from 表 ——查出的是前3个,而不是第3个 或 select * from 表 where name='C'——用name做限定条件不可取TO crazyswan(crazy) select top 1 * from ( select top 3 * from TABLE order by CREATETIME desc) 有错误
加一个别名 select top 1 * from ( select top 3 * from TABLE order by CREATETIME desc) as b
也不对 select top 3 * from TABLE order by CREATETIME desc取到 6 5 4 再 select top 1 * 则取到的是 6 F 2004-9-1 17:01
select top 1 * from 表名 where id not in (select top 2 * from 表名)
from (
select top n * //n表示你要查询的第n条记录,比如取第3条记录,n=3
from table
order byu desc
)
或 select * from 表 where name='C'
ID为表具有唯一值的任何字段
select top 1 * from TABLE where ID not in (select top 2 * from TABLE)
有问题,where ID not in (select top 2 * from TABLE) 在not in列表中只能指定一个字段ID,但是select top 2 * from TABLE 查出的是所有字段TO long0104()
select top 3 * from 表 ——查出的是前3个,而不是第3个
或 select * from 表 where name='C'——用name做限定条件不可取TO crazyswan(crazy)
select top 1 *
from ( select top 3 * from TABLE order by CREATETIME desc)
有错误
select top 1 *
from ( select top 3 * from TABLE order by CREATETIME desc) as b
select top 3 * from TABLE order by CREATETIME desc取到
6
5
4
再 select top 1 * 则取到的是
6 F 2004-9-1 17:01