SQL与where和until的条件

时间:2012-02-09 14:52:41

标签: mysql

我如何结合以下内容:

        IF( IF(news_publish_until IS NOT NULL,
               news_publish_until, NOW())
        >= NOW(),1,0)

        IF( IF(news_publish_until IS NOT NULL,
               news_publish_until, NOW())
        <= NOW(),1,0)

如果条件为TURE,则SQL必须返回1,IE属于Publish from / until日期。此外,如果日期为空,则设置NULL而不是0000-00 ....

这是我到目前为止所处的位置:

    IF(news_publish_from >= NOW() AND (news_publish_until >= NOW() OR news_publish_until IS NULL), 1,
         IF(news_publish_from >= NOW() AND (news_publish_until &lt;= NOW() OR news_publish_from IS NULL), 1, 0))

1 个答案:

答案 0 :(得分:0)

嗯,我想我明白了。你认为你正在寻找这样的东西:

select *,
  (news_publish_from <= now() or news_publish_from is null) and
  (news_publish_until >= now() or news_publish_until is null)
  as result
from supportContacts

所以,我认为你应该把它放在你的sql标签中:

news_publish_from <= now() or news_publish_from is null) and
(news_publish_until >= now() or news_publish_until is null)

你可以玩它here。希望这有帮助