成绩查询

mhxcy 2007-09-27 10:46:54
有一成绩表,结构如下:
考号 char(9)
姓名 char(6)
班级 char(2)
语文 int
数学 int
英语 int
总分 int
考试名称 char(20)
表中有五个班级3次考试成绩,如何查询某班某次考试总分前100名有多少人?
如何查询某班3次考试总分前100名各有多少人?
...全文
156 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangys 2007-09-28
  • 打赏
  • 举报
回复

insert tb(考号,姓名,班级,总分,考试名称)
select '1','aaa','c1',100,'bbb' union all
select '2','bbb','c1',50,'bbb' union all
select '3','cccc','b',100,'bbb' union all
select '4','bbb','c1',50,'ccc' union all
select '5','aaa','c1',100,'ccc' union all
select '5','cccc','b',50,'ccc'


--某班某次考试总分前100名有多少人
select count(*) from (

select 考号,姓名,班级,总分,考试名称,sorId=(select count(distinct 总分) from tb where a.考试名称=考试名称 and a.总分<=总分)
from tb a ) c
where 考试名称='bbb' and 班级='c1' and sorId<=200


--查询某班3次考试总分前100名各有多少人(刚才每班只考试三次。如果多于三次,请加班级OR)
select count(*) from (

select 考号,姓名,班级,总分,考试名称,sorId=(select count(distinct 总分) from tb where a.考试名称=考试名称 and a.总分<=总分)
from tb a ) c
where 班级='c1' and sorId<=200
dawugui 2007-09-27
  • 打赏
  • 举报
回复
总分前100名中各班各有多少人?
考试名称 char(20)来区分这三次考试?

34,590

社区成员

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

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