本例数据库表:Nodes(id,name,level)
如果要取出数据库中第N大的数据记录,则可以这样写SQL语句:
select * from nodes where id=(select Min(id) as id from nodes where id in(select top N id from nodes order by id Desc))
注意:此处N是你选取的第几大的数据记录
同理:第N小的数据记录的SQL语句
select * from nodes where id=(select Max(id) as id from nodes where id in(select top N id from nodes order by id asc))
如果要取出数据库中第N大的数据记录,则可以这样写SQL语句:
select * from nodes where id=(select Min(id) as id from nodes where id in(select top N id from nodes order by id Desc))
注意:此处N是你选取的第几大的数据记录
同理:第N小的数据记录的SQL语句
select * from nodes where id=(select Max(id) as id from nodes where id in(select top N id from nodes order by id asc))
浙公网安备 33010602011771号