2010-09-08 62 views
0

在以下示例中,我獲取了大於'2009-11-29'以及NULL和'0000-00-00'的所有值。有沒有其他方法可以獲得相同的結果?選擇無效日期

mysql>select * from totest; 
+---------------------+ 
| stime    | 
+---------------------+ 
| 0000-00-00 00:00:00 | 
| 2009-12-12 12:22:32 | 
| 0000-00-00 00:00:00 | 
| 2009-01-12 12:22:32 | 
| 0000-00-00 00:00:00 | 
| NULL    | 
+---------------------+ 
6 rows in set (0.00 sec) 

mysql>select * from totest where If(stime!='0000-00-00', stime >= '2009-11-29', 1); 
+---------------------+ 
| stime    | 
+---------------------+ 
| 0000-00-00 00:00:00 | 
| 2009-12-12 12:22:32 | 
| 0000-00-00 00:00:00 | 
| 0000-00-00 00:00:00 | 
| NULL    | 
+---------------------+ 
5 rows in set (0.00 sec) 
+1

你嘗試過或 「OR」 更大? – sheeks06 2010-09-08 07:04:03

+0

你能否澄清你的問題?你想要返回1)無效(零)和空日期? 2)選擇'正確'的日期大於'2009-11-29' – 2010-09-08 07:11:14

+0

我正在尋找「或」。有時候事情很簡單,在你眼前,你仍然看不到它們! – shantanuo 2010-09-08 07:25:56

回答

0

選擇無效日期(零日期和零)

 select * from totest 
     where stime = '0000-00-00' 
     OR stime IS NULL 

只選擇有效的日期比 '2009-11-29'

 select * from totest 
     where stime != '0000-00-00' 
     AND stime IS NULL 
     AND stime >= '2009-11-29' 
0

你可以試試這個嗎?

select * 
from totest 
where 
    stime = '0000-00-00' 
    OR stime IS NULL 
    OR stime < '2009-11-29'