当前位置: 代码迷 >> Sql Server >> 取数据有关问题
  详细解决方案

取数据有关问题

热度:104   发布时间:2016-04-27 19:37:51.0
取数据问题
表只有1个字段
item
4444
333
222
1111

我想取出上面数第2个怎么取?谢谢

------解决方案--------------------
select top 1 item from table where item not in (select top 1 item from table order by item desc)
------解决方案--------------------
select top 1 item from table where item not in (select top 1 item from table order by item desc) order by item desc
------解决方案--------------------
create table tb(item int)
insert into tb values(4444)
insert into tb values(333)
insert into tb values(222)
insert into tb values(1111)

select top 1 * from tb where item not in (select top 1 * from tb)
drop table tb

/*
item
-----------
333

(所影响的行数为 1 行)
*/

  相关解决方案