我有一個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'
你需要這個計數嗎(我的意思是你需要返回的數據中的remaining_attempts)? – 2013-02-19 22:29:42
沒有必要返回remaining_attempts。 – 2013-02-19 22:38:24