限制返回的记录数

jing1979 2000-04-24 09:36:00
我希望使用select语句返回前三名学生。可我用 select top 3 * from table order by score的话就只能返回三条记录。但是第三名有并列的情况搞不定。
帮帮我吧
...全文
131 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Axiong 2000-04-28
  • 打赏
  • 举报
回复
select top 3 with ties * from table order by score desc
Axiong 2000-04-28
  • 打赏
  • 举报
回复
select top 3 with ties * from table order by score 就可以了
其他方法都不好
tanghuan 2000-04-25
  • 打赏
  • 举报
回复
对不起
select distinct score
into #temptable
from table

select *
from table
where score > (
select max(score)
from (
select b.score,count(*) "order"
from #temptable a,#temptable b
where a.score>=b.score
group by b.score
having count(*)<3
) a
)
tanghuan 2000-04-25
  • 打赏
  • 举报
回复
select distinct score
into #temptable
from table

select *
from table
where score > (
select max(score)
from (
select b.score,count(*) "order"
from #temptable a,#temptable b
where a.score<=b.score
group by b.score
having count(*)<3
) a
)
jing1979 2000-04-24
  • 打赏
  • 举报
回复
用select top 3 with ties * from table order by score

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧