回 帖 发 新 帖 刷新版面

主题:求一sql语句

求一字段的降序第n条纪录
如有一个学生表,有一个字段是语文分数的字段,我想求此学生表中按降序的第10位的语文分数是多少分

回复列表 (共5个回复)

沙发

假如是oracle就很容易,sql server不懂。。。

板凳

我们刚开始学习数据库 呵呵 过几天就能解决了

3 楼

create table #t(
id int not null identity(1,1) primary key,
score int
)
go
declare @i int
set @i=1
while @i<=100
begin
    insert into #t(score) values(ceiling(rand()*90))
    set @i=@i+1
end

select top 1 * from (select top 10 * from #t order by score desc) t

drop table #t

4 楼

SELECT TOP 1 * FROM XSB WHERE ID NOT IN
      (SELECT TOP 9 ID FROM XSB ORDER BY YW DESC ) 
              ORDER BY YW DESC

5 楼

第十位
select top 1 * from
(select top 10 * from table_name order by score desc) t order by score asc

我来回复

您尚未登录,请登录后再回复。点此登录或注册