在以下示例中,我得到的所有值都大于'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)
答案 0 :(得分:0)
你可以尝试一下吗?
select *
from totest
where
stime = '0000-00-00'
OR stime IS NULL
OR stime < '2009-11-29'
答案 1 :(得分: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'