3

SQLフィドルを作成しました

ここに画像の説明を入力してください結果を表示していますが、2行目のイベントpqrが表示されません。誰でも助けてください。

開始日と終了日がnullでない場合、end_dateは今日以上である必要があり、現在の使用とmaxusesがnullでない場合、現在の使用はmax use未満であるか、すべてのデータがnullであり、イベント名と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を除くすべてのデータがnullであるような行です。

私がすでに修正したもう1つの間違いは、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

両方WHEREの句にはstart_date is not null制約(およびその他のいくつか)があり、そのレコードの存在start_date(または他のすべてのフィールド)により、結果に表示されなくなります。null

于 2013-02-27T18:42:02.800 に答える
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 に答える