MySQL Where子句为两个独立的值使用相同的键两次

时间:2022-10-18 21:42:43

I am generating the following query

我正在生成以下查询

SELECT * FROM Report WHERE submittedOn >= :minDateFilter 
AND submittedOn <= :maxDateFilter AND non_issue = 1 AND 
non_issue = 0 ORDER BY submitted

However, I'm not getting anything returned (it works fine if I omit: AND non_issue = 1 AND non_issue = 0, or omit just one of these, but nothing is being returned when both of these clauses are present.

但是,我没有得到任何返回值(如果我省略:和non_issue = 1和non_issue = 0,或者只省略其中的一个,那么就可以工作得很好,但是当这两个子句都存在时,不会返回任何值。

Ideally I'd like to keep the statement how it is, as it's generated on the fly and I'd like to be able to display both types of report from the same query.

理想情况下,我希望保持语句的原样,因为它是动态生成的,我希望能够显示来自同一查询的两种类型的报告。

I feel like my syntax might be incorrect, but it's not throwing any errors, any suggestions?

我觉得我的语法可能是不正确的,但它没有抛出任何错误,有什么建议吗?

2 个解决方案

#1


3  

non_issue can not have 2 values at same time on a given row. I think you would like to use OR:

在给定的行上,non_issue不能同时有两个值。我想你会使用或:

 SELECT * FROM Report WHERE submittedOn >= :minDateFilter 
AND submittedOn <= :maxDateFilter AND (non_issue = 1 OR 
non_issue = 0) ORDER BY submitted

#2


1  

You can use the IN instead of non_issue = 1 AND non_issue = 0 condition.

您可以使用IN而不是non_issue = 1和non_issue = 0条件。

The same entry can't be non_issue equal to 0 and 1 same time.

同一项不能同时为0和1。

SELECT * 
FROM Report 
WHERE submittedOn >= :minDateFilter AND 
      submittedOn <= :maxDateFilter AND 
      non_issue IN (0, 1)
ORDER BY submitted

#1


3  

non_issue can not have 2 values at same time on a given row. I think you would like to use OR:

在给定的行上,non_issue不能同时有两个值。我想你会使用或:

 SELECT * FROM Report WHERE submittedOn >= :minDateFilter 
AND submittedOn <= :maxDateFilter AND (non_issue = 1 OR 
non_issue = 0) ORDER BY submitted

#2


1  

You can use the IN instead of non_issue = 1 AND non_issue = 0 condition.

您可以使用IN而不是non_issue = 1和non_issue = 0条件。

The same entry can't be non_issue equal to 0 and 1 same time.

同一项不能同时为0和1。

SELECT * 
FROM Report 
WHERE submittedOn >= :minDateFilter AND 
      submittedOn <= :maxDateFilter AND 
      non_issue IN (0, 1)
ORDER BY submitted