MGPFG 2021-06-29 16:46 采纳率: 75%
浏览 17

在这个程序中,查出最高分就查不出最低分课程,不知道错在哪儿了呜呜

USE StudentScore
GO 
CREATE PROCEDURE ST_XYFX @StudentID int
/*存储过程ST_XYFX指定的参数@StudentID是输入参数*/
AS
SELECT CourseName
from
Student,score,Course 
where student.StudentID=Score.StudentID and Course .CourseID=Score.CourseID and Student.StudentID=@StudentID
GROUP BY CourseName

SELECT AVG(Grade) AS '平均分'
FROM Course a,Score b,Student c
where b.StudentID = @StudentID and a.CourseID =b.CourseID and b.StudentID =c.StudentID 

select d.CourseName as '最高分课程'
from
(SELECT MAX(Grade) AS '最高成绩',Student.StudentID ,CourseName 
FROM Student join score
on student.StudentID=Score.StudentID
join Course
on Course.CourseID=Score.CourseID
where Grade =(Select max(Grade) From Score
where  Student.StudentID= @StudentID)
Group BY Student .StudentID ,CourseName,Grade )d
where d.StudentID= @StudentID
 
select e.CourseName as '最低分课程'
from
(SELECT MIN(Grade) AS '最低成绩',Student.StudentID ,CourseName  
FROM Student join score
on student.StudentID=Score.StudentID
join Course
on Course.CourseID=Score.CourseID
where Grade =(Select min(Grade) From Score
where  Student.StudentID= @StudentID)
Group BY Student .StudentID ,CourseName,Grade )e
where e.StudentID= @StudentID

  • 写回答

1条回答 默认 最新

  • 4935同学 全国云计算技术与应用技能大赛获奖者 2023-03-10 09:39
    关注

    group by后使用max min avg函数就可以了 写的太复杂了

    评论

报告相同问题?

悬赏问题

  • ¥15 vue3页面el-table页面数据过多
  • ¥100 vue3中融入gRPC-web
  • ¥15 kali环境运行volatility分析android内存文件,缺profile
  • ¥15 写uniapp时遇到的问题
  • ¥15 vs 2008 安装遇到问题
  • ¥15 matlab有限元法求解梁带有若干弹簧质量系统的固有频率
  • ¥15 找一个网络防御专家,外包的
  • ¥100 能不能让两张不同的图片md5值一样,(有尝)
  • ¥15 informer代码训练自己的数据集,改参数怎么改
  • ¥15 请看一下,学校实验要求,我需要具体代码