简体   繁体   English

MySQL优先级条件与where子句

[英]Mysql priority condition with where clause

I try to check two conditions when checking first condition if it is true then ignore second condition. 在检查第一个条件是否为真时,我尝试检查两个条件,然后忽略第二个条件。 if first condition false then check second condition. 如果第一个条件为假,则检查第二个条件。

here query like this 在这里这样查询

select * from region_daten inner join werte_inc where datum = today or datum = yesterday"

桌子看起来像这样

here returns today and yesterday because both are true but before 11:30 am i have only yesterday date after 11:30 am i have both dates. 这里返回今天和昨天,因为两者都是正确的,但是在上午11:30之前,我只有昨天的日期,在上午11:30之后,我都有两个日期。 when i do with 'or' i got both dates data. 当我使用“或”时,我得到了两个日期数据。 but i need to show if date is today date i have to display today date data. 但是我需要显示日期是否是今天的日期,我必须显示今天的日期数据。 if not i have to display yesterday data. 如果不是,我必须显示昨天的数据。

Let's create a truth table: 让我们创建一个真值表:

date = today | date = yesterday | desired result
-------------+------------------+---------------
true         | true             | true
true         | false            | true
false        | true             | true
false        | false            | false

If this table is correct according to Your question, then what You are looking for is an OR: 如果根据您的问题此表是正确的,那么您正在寻找的是OR:

SELECT *
FROM table 
WHERE date = today OR date = yesterday

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM