selecting invalid dates
In the following example, I am getting all the values greater than '2009-11-29' as well as NULL and '0000-00-00'. Is there any other way to get the same results?
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)
Selecting invalid dates (zero dates and null)
select * from totest
where stime = '0000-00-00'
OR stime IS NULL
Selecting only valid dates greater than '2009-11-29'
select * from totest
where stime != '0000-00-00'
AND stime IS NULL
AND stime >= '2009-11-29'
Can you try this out?
select *
from totest
where
stime = '0000-00-00'
OR stime IS NULL
OR stime < '2009-11-29'
精彩评论