0

我正在尝试创建查询,该查询返回通过考试的学生列表,至少失败次数为 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*/
4

1 回答 1

1

)您的子查询似乎在子句之后有一个太多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*/
于 2012-09-14T19:18:19.237 回答