我有两个查询。返回班级平均数,最低成绩和最高成绩。第二个返回特定的学生结果。我试图将这两个查询合并为一个查询,以便显示具体的学生结果以及该班级的最小,最大和平均结果。我试过的任何东西都会导致错误。有没有简单的我失踪?下面的两个查询:返回平均值以及特定行
SELECT Module.ModuleTitle, Module.ModuleDescription,
MIN(StudentModule.StudentGradeFinal) as lowres,
MAX(StudentModule.StudentGradeFinal) as topres,
AVG(CAST(StudentModule.StudentGradeFinal as DECIMAL(9,2))) as averageres
FROM StudentModule
join Module on StudentModule.ModuleId = Module.ModuleId
WHERE Semester = 'Spring'
AND Module.ModuleId in
(
SELECT Module.ModuleId FROM Module
Join StudentModule on Module.ModuleId = StudentModule.ModuleId
Where StudentId = '40104002'
)
GROUP BY Module.ModuleTitle, Module.ModuleDescription
SELECT Module.ModuleTitle, Module.ModuleDescription, StudentGradeFinal
FROM StudentModule
join Module on StudentModule.ModuleId = Module.ModuleId
WHERE Semester = 'Spring' AND StudentModule.StudentId = '40104002'
提供样本数据和预期结果。目前还不清楚你想要输出什么。 –