gpt4 book ai didi

mysql - 仅当字段不为空时如何添加where条件

转载 作者:行者123 更新时间:2023-11-29 04:33:08 25 4
gpt4 key购买 nike

目前我有像 where p.id>5 和 p.addedDate > now() 这样的 where 子句。我想要类似 p.id>5 if (NotNullp.aadedDate) and p.addedDate > now() else 的东西;是否可以仅在字段值为 not null 时添加带条件的 And 运算符。所以如果 aadedDate 是 null 那么查询应该像 p.id>5 只是不检查 p.addedDate 应该应用

最佳答案

我们可以使用IS NULL检查该字段是否为 nullOR 条件将返回 TRUE,如果 addedDate 为 NULL

WHERE p.id > 5 AND 
(p.addedDate IS NULL OR p.addedDate > NOW())

关于mysql - 仅当字段不为空时如何添加where条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53514974/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com