[英]MySQL SELECT If Statement WHERE Condition
I created a module for rendering overtime. 我创建了一个用于渲染超时的模块。 In the module you will select your approving person and it will be maximum of 3 persons. 在模块中,您将选择批准人,最多3人。
The scenario is that I will display all approved overtimes if manager1_date
is not NULL
, manager2_date
is not NULL
and manager3_date
is not NULL
. 该方案是,如果manager1_date
不为NULL
, manager2_date
不为NULL
以及manager3_date
不为NULL
,我将显示所有批准的加班。 But as i said, it can be only 1,2 or 3 approving person. 但是正如我所说,它只能是1,2或3个批准人。 what if i applied then i have only 2 approving persons, it should be if manager1_date
is not NULL
and manager2_date
is not NULL
. 如果我申请的话我只有2个批准人,那应该是manager1_date
不为NULL
且manager2_date
不为NULL
。
I tried this query: 我尝试了以下查询:
Select * from table1
where manager1_date is not null
AND (manager2_date is not null or manager3_date is not null)
In PHP, it displays the record but the record has 3rd approving person which is manager3_date
is NULL
. 在PHP中,它显示记录,但该记录具有第三批准人,即manager3_date
为NULL
。 it should not display the record until the approving persons are filled out. 在填写批准人之前,它不应显示记录。
I think you are saying that all three managers must approve. 我认为您是在说所有三位经理都必须批准。 If so your query would be: 如果是这样,您的查询将是:
SELECT *
FROM table1
WHERE manager1_date IS NOT null
AND manager2_date IS NOT null
AND manager3_date IS NOT null
I'm not sure if I understand your question, but if you need to see when all three manager dates are not null, get rid of the "or". 我不确定我是否理解您的问题,但是如果您需要查看所有三个经理日期都不为空的话,请摆脱“或”。
Select *
from table1
where manager1_date is not null
AND manager2_date is not null
AND manager3_date is not null
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.