列出各班成绩前三的学生纪录

kyle245 2006-12-19 04:21:27
字段: id class math
请问如何查询各班成绩(字段-math)前三的记录?
...全文
171 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
chd2001 2006-12-19
  • 打赏
  • 举报
回复
select a.* from t a,(select top 3 distinct class,math from t order by math desc) b
where a.class=b.class and a.math=b.math
包含并列分数的情况
kyle245 2006-12-19
  • 打赏
  • 举报
回复
上面的 [表] 和 [t] 没看懂
我这里只有一张表就叫 t 吧
字段: id class math
1 3 80
2 3 78
4 4 60
......
然后查询每个班级(class)成绩(math)排名前三的纪录.
子陌红尘 2006-12-19
  • 打赏
  • 举报
回复
select t.* from 表 t where t.id in(select top 3 id from 表 where class=t.class order by math desc)
子陌红尘 2006-12-19
  • 打赏
  • 举报
回复
select t.* from 表 t where t.id in(select top 3 id from 表 where class=t.class order by math desc)

27,579

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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