create table test(id int,value nvarchar(10))
insert test 
select 1,'没' union all
select 2,'有' union all
select 3,'测' union all
select 4,'试' union all
select 5,'数' union all
select 6,'据' select a.id,a.value
from (
select RowNumber = ROW_NUMBER() OVER(ORDER BY id DESC),
 id,
 value 
from test
) a
where a.RowNumber=2

解决方案 »

  1.   

    就比如获取学生的成绩的数据    我已经把前三名得到了   可是要怎么得到第二名的数据
    name        sex        phone       score
    张三      男     123123       55




    就比如这样的
      

  2.   

    2005以上的,
    select *
    from (
    select row_number()over(partition by name order by score)id,*
    from 你的结果集
    )a
    where id=2
      

  3.   

    select * from 
    (
    select row_number()over(partition by name order by score
    )
    d,*from
    (
    select top 3 * from charts order by Score desc
    )a where id=2
      

  4.   

    没用呀
    消息 102,级别 15,状态 1,第 8 行
    '2' 附近有语法错误。
    因为row_number() over  没用过  不了解
      

  5.   


    select * from 
    (
    select row_number()over(partition by name order by score desc
    )
    d,*from charts)a where id=2是这个语句吧   不过查出来的不对啊
      

  6.   

    select * from 
    (
    select row_number()over(partition by name order by score desc)id,*
    from charts)a where id=2你多了一个括号,少了一个i...用我上面的,另外如果数据不对,你要考虑一下那个desc还是asc
      

  7.   

    select top 1 * from students where score not in(select top 1 score from students order by score desc)
    按我这个格式来写  把表名和列名改下就行了!