我有一张存储学生考试成绩的表格。在该表中,我有一个nvarchar
列REMARKS
;如果获得的标记小于通过标记,系统会在该特定列中将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'
答案 0 :(得分:1)
以下查询返回' fail'在ExamType
和year
中,学生有多个失败
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