我有一个 MySQL 语句,我需要一些帮助。我正在正确提取数据,但我只需要一些帮助,排除不需要的记录。如果候选人剩余尝试次数等于 0,我不想提取该记录,但如您所见,我正在使用子查询来生成候选人可能进行的重新挖掘尝试次数。
有没有办法使用 WHERE 语句中的剩余尝试字段来排除不需要的记录?
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'