排名之解决

wjg315 2008-04-19 04:24:33
成绩表字段如下
ID CourseID studentID 考试时间 成绩 班级ID

现能否在VB的 Datagrid 中实现如下形式的显示结果(某班某学期成绩)

编号 studentID 课程名1 课程名2 ... 总分 平均分 名次


课程名在另一个表中
我用ADO控件实现,编号,名次,条件(WHERE)将如何增加

以下是他们放过来的,但是编号,与名次未有解决而且我要的是某班某学期的排名

declare @s varchar(8000)

select @s = isnull(@s+',','') + '[CourseID('+ltrim(CourseID)+')]=max(case when CourseID = '+
ltrim(CourseID) + ' then Score else 0 end)'
from (select distinct CourseID from Scores ) a

exec(' select studentID,'+@s+',总分=sum(Score) ,平均分= avg(Score) from Scores group by studentID order by sum(Score) desc')


...全文
111 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wjg315 2008-04-19
  • 打赏
  • 举报
回复
提取的结果是所有的CourseID这了段
而要实现的结果的某个班某个学期的,因为所有的班级并非都开了相同的科目
你能具体写一下吗
用的是ADODC控件,和DataGrid的,(ClassID,CourseTerm通过两下列表框获取的)
-狙击手- 2008-04-19
  • 打赏
  • 举报
回复
set @WHERE =' classid = 1 and courseterm = 3'

要是classid 是varchar
set @WHERE =' classid = ''1'' and courseterm = 3'
wjg315 2008-04-19
  • 打赏
  • 举报
回复

VB+SQL2000的
我都试验了好多他们发过的代码,但都没有能完整的解决
你能具体写一下吗
用的是ADODC控件,和DataGrid的,(ClassID,CourseTerm通过两下列表框获取的)
wjg315 2008-04-19
  • 打赏
  • 举报
回复

你给的,那@WHERE应该啥个写呢(如ClassID='04B',CourseTerm='下学期')
-狙击手- 2008-04-19
  • 打赏
  • 举报
回复
declare @s varchar(8000)  
declare @where varchar(100)

select @s = isnull(@s+',','') + '[CourseID('+ltrim(CourseID)+')]=max(case when CourseID = '+
ltrim(CourseID) + ' then Score else 0 end)'
from (select distinct CourseID from Scores ) a

exec(' select studentID,'+@s+',总分=sum(Score) ,平均分= avg(Score),名次=identity(int,1,1) into tmp from (select * from Scores where'+ @where +')a group by studentID order by sum(Score) desc')

select * from tmp
drop table tmp
Limpire 2008-04-19
  • 打赏
  • 举报
回复
SQL用2005还是2000啊

27,579

社区成员

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

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