2016-06-02 28 views
1

"IN"節の値はどのように除外しますか?"IN"節の値を除外します

$Graduates = "45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,73,74,75,76,84,85,86,87,88,89,91, 
     92,93,94,95,96,98,99,100,101,103,104,105,106,107,108,109,110,111,112,113,114,117,122,123,126,127,131,135,136,137, 
     138,139,140,142,143,146,156"; //MajorID 

    $QryFirstNursing = "SELECT * 
       FROM ".$SemYearSettings->getYearSem($Enroll)." 
       WHERE ".$SemYearSettings->getYearSem($Enroll).".MajorID IN (".$Graduates.") 
       AND ".$SemYearSettings->getYearSem($Enroll).".Category = ".$CategoryIDN;   
    $resultFirstNursing = openQry($QryFirstNursing); 

助けてください。ありがとう

+0

'majorId Not In 'を使用します – Ali

+0

特定の値を除外しますか? –

+1

どのように卒業生を取得しますか?あなたがそれらを取得するために使用するクエリが存在すれば、存在しない可能性があります。つまり、最も効率的です。 '... WHERE NOT EXIST(SELECT ID ...卒業生になるクエリ) 'または' NOT IN ) 'この質問は役に立ちましたか?http://stackoverflow.com/questions/8702797/mysql-where-clause-which-excludes-results-in-subquery – ArtisticPhoenix

答えて

2

@Ardit Meti rights。これは次のようになります:

$Graduates = "45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,73,74,75,76,84,85,86,87,88,89,91,92,93,94,95,96,98,99,100,101,103,104,105,106,107,108,109,110,111,112,113,114,117,122,123,126,127,131,135,136,137,138,139,140,142,143,146,156"; //MajorID 

    $tableName = $SemYearSettings->getYearSem($Enroll); 

    $QryFirstNursing = "SELECT * 
      FROM {$tableName} 
      WHERE {$tableName}.MajorID NOT IN ('{$Graduates}') 
      AND {$tableName}.Category = {$CategoryIDN}";   

    $resultFirstNursing = openQry($QryFirstNursing); 
関連する問題