3

我创建了sql fiddle

在此处输入图像描述并显示结果,但我没有得到第二行事件 pqr。任何人都可以帮助我。

我想要那些开始日期和结束日期不为空的行,那么 end_date 今天必须等于或大于,如果当前使用和 maxuse 不为空,那么当前使用小于 max use 或所有数据为空,接受事件名称和 id。

提前致谢

4

3 回答 3

1

您的 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您检查的部分只是greater.

很可能你想要这个声明

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
);
于 2013-02-27T18:48:06.687 回答
0

我想这就是你要找的

   select * from event 
  where ((start_date is not null)&&(end_date is not null)&&(end_date>= curdate()))

 OR ((max_use is not null)&&(current_use is not null)&&(current_use < max_use ))
 or ( (start_date is  null ) and (end_date is  null) and (max_use is  null)
   and (current_use is  null))

演示 SQLFIDDLE

于 2013-02-27T19:13:13.547 回答
0

这两个WHERE子句都有一个start_date is not null约束(加上其他一些),并且该记录的存在start_date(或每个其他字段)null使其不会出现在结果中。

于 2013-02-27T18:42:02.800 回答