我尝试使用 CASE WHEN 语句,但似乎我错过了什么,或者这不是正确的做法。@APASS 参数使查询返回通过或未通过指定考试的人。
SELECT ID, Name,ZipCode,Mobile
FROM tblStudent
WHERE (Sex = @Sex) AND (ID IN
(SELECT StID
FROM tblTest
WHERE (TestID = @TestID) AND
CASE WHEN @APass = TRUE THEN (Score IN (27, 28, 29, 30))
ELSE (Score NOT IN (27, 28, 29, 30))
END
GROUP BY StID, TestID
HAVING (COUNT(*) = @Times)))