学生结果基于使用SQL Server的已通过和失败的备注

时间:2017-10-26 08:14:52

标签: sql-server

我有一张存储学生考试成绩的表格。在该表中,我有一个nvarcharREMARKS;如果获得的标记小于通过标记,系统会在该特定列中将Pass/Fail添加到Remarks

现在问题是我显示了获得总分的整个结果,并且如果学生已经通过或失败,也会显示基于

之类的查询
If remarks = 'Fail' 

并且失败是该考试中的多个科目而不是显示失败否则通过。我搜索并尝试了很多但没有运气。任何人都可以告诉我如何完成它?

谢谢!

更新: 到目前为止尝试过:

SELECT 
    StudentName,
    Year,
    ExamType,
    SUM(TotalMarks) AS TotalMarks,
    SUM(ObtainedMarks) AS ObtMarks  
FROM 
    [dbo].[Exam]
WHERE
    ExamType = @Type AND Year = @Year

寻找类似的查询:

CASE WHEN [Remarks] = 'Fail' and having count > 1  THEN 'Fail' ELSE 'Pass' End as 'Status' 

1 个答案:

答案 0 :(得分:1)

以下查询返回' fail'在ExamTypeyear中,学生有多个失败

SELECT StudentName
  ,@Year
  ,@Type
  ,Sum(TotalMarks) as TotalMarks
  ,Sum(ObtainedMarks) as ObtMarks  
  ,CASE WHEN Count(CASE WHEN [Remarks] = 'Fail' THEN 1 END) > 1 THEN 'Fail' ELSE 'Pass' End as 'Status'
FROM [dbo].[Exam]
Where ExamType = @Type And Year = @Year
Group by StudentName