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

サブクエリの句の)直後に1 つ多すぎるようです。これらは行に移動する必要があります。INHAVING

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 に答える