>我正在尝试创建查询,该查询返回通过考试后通过考试的学生列表,至少 X 次失败。为此,我编写了以下查询,但也收到以下错误:
IN 子句中的值列表错误。无法分析查询文本。
我确定 IN 子句中的值列表很好,尽管我不明白的是它为什么抱怨?!这是有问题的查询:
SELECT StudentID
FROM tblStudents
WHERE (Sex = @Sex) AND (StudentID IN
(SELECT StudentID
FROM tblTest
WHERE (TestID = @TestID) AND (@APass = 'true') AND (Score IN (27, 28, 29, 30)))
GROUP BY StudentID, TestID
HAVING (COUNT(*) = 1))/*By this i meant find the the user who has passed the exam (finally)*/
AND (StudentID IN
(SELECT StudentID
FROM tblTest
WHERE (TestID = @TestID) AND (Score NOT IN (27, 28, 29, 30)))
GROUP BY StudentID, TestID
HAVING (COUNT(*) >= @Times))/*And By this i meant only return students which passed the exam after x times of failing it*/
您的子查询似乎在 IN
子句之后有太多)
- 这些应该移动到HAVING
行。
SELECT StudentID
FROM tblStudents
WHERE (Sex = @Sex) AND (StudentID IN
(SELECT StudentID
FROM tblTest
WHERE (TestID = @TestID) AND (@APass = 'true') AND (Score IN (27, 28, 29, 30))
GROUP BY StudentID, TestID
HAVING (COUNT(*) = 1)))/*By this i meant find the the user who has passed the exam (finally)*/
AND (StudentID IN
(SELECT StudentID
FROM tblTest
WHERE (TestID = @TestID) AND (Score NOT IN (27, 28, 29, 30))
GROUP BY StudentID, TestID
HAVING (COUNT(*) >= @Times)))/*And By this i meant only return students which passed the exam after x times of failing it*/