2013-02-19 65 views
0

我有一個MySQL語句,我需要一點幫助。我拉正確的數據,但我只需要一些幫助,排除不需要的記錄。如果候選剩餘嘗試等於0,我不想拉取該記錄,但正如您所看到的,我正在使用子查詢來生成候選人可能具有的提醒嘗試次數。如何從查詢中排除不需要的記錄

有沒有辦法使用WHERE語句中的remaining_attempts字段來排除不需要的記錄?

SELECT (
       SELECT count(*) AS Number_Attempts_Used 
       FROM candidate_exam_record 
       WHERE candidate_exam_record.idcandidate_eligibilty = candidate_eligibilty.idcandidate_eligibilty 
      ) AS remaining_attempts 
      , (
       SELECT CASE WHEN count(*) > '0' THEN candidate_exam_record.idcandidate_eligibilty END 
       FROM candidate_exam_record 
       WHERE candidate_exam_record.idcandidate_eligibilty = candidate_eligibilty.idcandidate_eligibilty) AS EL_ID 
    FROM candidate_eligibilty 
      INNER JOIN candidate ON candidate_eligibilty.idcandidate = candidate.idcandidate 
      INNER JOIN exam ON candidate_eligibilty.exam_id = exam.exam_id 
      INNER JOIN jurisdiction ON exam.jurisdiction_id = jurisdiction.jurisdiction_id 
    WHERE jurisdiction.jurisdiction_id = 'xxxx' 
      AND candidate_eligibilty.eligibility_end_date >= '2013-02-19' 
      AND remaining_attempts > '0' 
+0

你需要這個計數嗎(我的意思是你需要返回的數據中的remaining_attempts)? – 2013-02-19 22:29:42

+0

沒有必要返回remaining_attempts。 – 2013-02-19 22:38:24

回答

0

這很雜亂,但它看起來對我很好。嘗試更改'0'只是普通的舊0。你將它存儲爲我認爲的INT,對不對?

+0

存在這種情況,remaining_attempts字段不是由子子查詢生成的表中的字段。 – 2013-02-19 22:40:20

+0

您能否看到實際存儲在remaining_attempts中的值的類型? – 2013-02-19 22:42:03