我已经创建了sql fiddle
并显示结果,但我没有得到第二行事件PQR。任何人可以帮助我。
我希望那些行的开始日期和结束日期如果不为空,则结束日期必须等于或大于今天,如果当前使用和最大使用不为空,则当前使用小于最大使用或所有数据都为空,接受事件名称和ID。
提前谢谢

最佳答案

您的select语句如下所示:

SELECT * FROM event
WHERE (
     (start_date IS NOT NULL)
  && (end_date IS NOT NULL)
  && (end_date >= curdate())
)
|| (
     (max_use IS NOT NULL)
  && (current_use IS NOT NULL)
  && (current_use < max_use)
);

这不是你想要的。尤其是你完全错过了or all data is null except event name and id部分。还有其他的错误(在你的问题文本或陈述中)。
pqr行就是这样一个行,除了事件名和id之外,所有数据都为空。
我已经纠正的另一个错误是您检查的greater or equal部分。
很可能你想要这个:
SELECT * FROM event
WHERE (
     start_date IS NOT NULL
  && end_date IS NOT NULL
  && end_date >= curdate()
)
||(
     max_use IS NOT NULL
  && current_use IS NOT NULL
  && current_use < max_use
)
|| (
     event is not null
  && start_date is null
  && end_date is null
  && max_use is null
  && current_use is null
);

关于mysql - 我没有在mysql查询中获得正确的数据。任何人都可以帮助我吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15119683/

10-10 00:44
查看更多