2010-09-08 67 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'