SQLフィドルを作成しました
結果を表示していますが、2行目のイベントpqrが表示されません。誰でも助けてください。
開始日と終了日がnullでない場合、end_dateは今日以上である必要があり、現在の使用とmaxusesがnullでない場合、現在の使用はmax use未満であるか、すべてのデータがnullであり、イベント名と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を除くすべてのデータが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
);
両方WHERE
の句にはstart_date is not null
制約(およびその他のいくつか)があり、そのレコードの存在start_date
(または他のすべてのフィールド)により、結果に表示されなくなります。null
私はこれがあなたが探しているものだと思います
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))