我創建sql fiddle我沒有得到正確的數據在mysql query.any可以幫助我嗎?
和顯示的結果,但我沒有得到第二排事件PQR .ANY一個可以幫我請。
我想那些行的開始日期和結束日期如果不爲空,那麼end_date必須等於或大於今天,如果當前use和maxuses不爲null,那麼當前使用少於max使用或所有數據爲null接受事件名稱和ID。
預先感謝
我創建sql fiddle我沒有得到正確的數據在mysql query.any可以幫助我嗎?
和顯示的結果,但我沒有得到第二排事件PQR .ANY一個可以幫我請。
我想那些行的開始日期和結束日期如果不爲空,那麼end_date必須等於或大於今天,如果當前use和maxuses不爲null,那麼當前使用少於max使用或所有數據爲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之外,所有的數據都是空的。
我已經糾正的另一個錯誤是greater or equal
部分,您檢查的部分只是greater
。
最大的可能是你想要這個statement:
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-27 19:10:37
很高興幫助。反問:你爲什麼想在這裏使用連接? – 2013-02-27 19:12:35
如果你不介意,我想知道使用連接可以做到嗎? – 2013-02-27 19:15:20
兩個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))
+1使用sqlfiddle。 – 2013-02-27 18:42:26
你想顯示id = 2,但是這個id全爲空! – 2013-02-27 19:00:44
我想從表中獲得信息,如果給出了開始日期和結束日期,那麼結束日期必須小於或等於今天的日期。如果最大用途是給定值,那麼當前使用必須小於max_uses,並且如果日期爲空且最大用途爲null然後得到那些行。 – 2013-02-27 19:01:21