我想做个对成绩的查询,可以按学号,专业+年级+学期分别进行查询,并且后面跟上合格情况,即统计出此学生成绩大于60的有多少门做的表如下
成绩表(score)
学号:stu_ID
课程号:course_ID
成绩:course_score
学期:semester课程表(course)
课程号:course_ID
课程名:course_name
课程类型:course_kind学生信息表(stu_info)
学号:stu_ID
姓名:stu_name
专业:stu_specialty课程确定表(course_fix)
专业: specialty
年级:grade
学期:semester
课程号: course_ID
我想用Datagrid来显示学生的成绩
显示格式大约为:学号 姓名 科目成绩 科目成绩 科目成绩
如:学号 姓名 英语 编译原理 C++语言...(其他科目) 合格科目数下面这个存储过程可查询出前面的内容,但是还不能统计后面的合格科目数
求高手指点
createt proc ddd
set @specialty   = ''  --专业
set @grade       = ''  --学年
set @semester    = ''  --学期
set @class1 = ''  --班级
as 
begin
declare @s varchar(8000)
set @s='select a.stu_ID as "学号",a.stu_name as "姓名"'select 
    @s=@s+',['+course_name+']=max(case b.course_ID when '+rtrim(a.course_ID)+' then b.course_score end)' 
from 
    course_fix a,course b 
where 
    a.course_ID = b.course_ID 
    and 
    a.stu_specialty = @specialty       --从课程确定表选择符合专业条件的课程信息
    and 
    a.stu_grade = @grade               --从课程确定表选择符合年级条件的课程信息
    and
    a.semester = @semester         --从课程确定表选择符合学期条件的课程信息
     --从课程表选择符合课程种类条件的课程信息set @s=@s+' from stu_info a,scoret b where' 
         +' a.stu_ID=b.stu_ID '
         +' and a.stu_specialty ='''+@specialty+''''    --从stu_info表筛选符合专业条件的学生信息
         +' and a.stu_class='''+@class1   +''''
 +' and b.semester      ='''+@semester +''''    --从score   表筛选符合学期条件的成绩信息
         +' group by a.stu_ID,a.stu_name'--print @sexec(@s)end 

解决方案 »

  1.   

    set @s='select a.stu_ID as "学号",a.stu_name as "姓名"'
    ---------------上面改为如下:
    set @s='select a.stu_ID as "学号",a.stu_name as "姓名",
                   合格数=sum(case when b.course_score>=60 then 1 else 0 end)'
      

  2.   

    createt proc ddd
    set @specialty   = ''  --专业
    set @grade       = ''  --学年
    set @semester    = ''  --学期
    set @class1 = ''  --班级
    as 
    begin
    declare @s varchar(8000)
    set @s='select a.stu_ID as "学号",a.stu_name as "姓名"'select 
        @s=@s+',['+course_name+']=max(case b.course_ID when '+rtrim(a.course_ID)+' then b.course_score end)' 
    from 
        course_fix a,course b 
    where 
        a.course_ID = b.course_ID 
        and 
        a.stu_specialty = @specialty       --从课程确定表选择符合专业条件的课程信息
        and 
        a.stu_grade = @grade               --从课程确定表选择符合年级条件的课程信息
        and
        a.semester = @semester         --从课程确定表选择符合学期条件的课程信息
         --从课程表选择符合课程种类条件的课程信息set @s=@s+',合格数=sum(case when b.course_score>=60 then 1 else 0 end) from stu_info a,scoret b where' 
             +' a.stu_ID=b.stu_ID '
             +' and a.stu_specialty ='''+@specialty+''''    --从stu_info表筛选符合专业条件的学生信息
             +' and a.stu_class='''+@class1   +''''
     +' and b.semester      ='''+@semester +''''    --从score   表筛选符合学期条件的成绩信息
             +' group by a.stu_ID,a.stu_name'--print @sexec(@s)end
      

  3.   

    set @s=@s+' from stu_info a,scoret b where' 
    ---------------上面改为如下:
    set @s=@s+',合格数=sum(case when b.course_score>=60 then 1 else 0 end) from stu_info a,scoret b where'