如何从查询中排除不需要的记录

时间:2013-02-19 22:27:15

标签: php mysql sql

我有一个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'

1 个答案:

答案 0 :(得分:0)

它很乱,但对我来说看起来还不错。尝试将'0'更改为普通的0。你把它存储为我认为的INT,对吗?