MySQL AND / OR SELECT语句中的多个值

时间:2018-07-11 19:48:00

标签: mysql

我有一个简单的查询,可以很好地工作:

SELECT 
     Name, JobStatus 
FROM 
     ScheduleRequest
WHERE
     ScheduleDate >= '2018-07-11' 
AND 
     JobStatus <> 6 

我需要检查同一字段“ JobStatus”中的不同值。当我尝试像这样更改查询时,我发现仅显示了最后一个值95?

SELECT 
     Name, JobStatus
FROM 
    ScheduleRequest
WHERE
    ScheduleDate >= '2018-07-11' 
    AND (JobStatus <> 6 
        OR JobStatus <> 0 
        OR JobStatus <> 1
        OR JobStatus <> 4
        OR JobStatus <> 95
    )

1 个答案:

答案 0 :(得分:3)

使用NOT IN表达式

SELECT 
     Name, JobStatus
FROM 
    ScheduleRequest
WHERE
     ScheduleDate >= '2018-07-11' 

    AND JobStatus NOT IN (6, 0, 1, 4, 95)